Re: JDBC SQL2005 Read encripting fields problem
- From: Joe Weinstein <joeNOSPAM@xxxxxxx>
- Date: Tue, 07 Nov 2006 08:45:27 -0800
Joe Weinstein wrote:
Big & Green wrote:
Good morning,
I am trying to read a field encrypted from SQL2005. My test code is this:
String sql = "";
sql = "select usuario " +
"from accesos where usuario = 'patito' and cast(DecryptByAsymKey(AsymKey_ID('EncriptadorOrbe'),clave_E, N'Contrasena') as varchar(100)) = 'patito2'"; ResultSet rs = null; Statement stmt = con.createStatement(); rs = stmt.executeQuery(sql);
System.out.println("Resultado:");
rs.next();
while(rs.next()){ System.out.println(rs.getString("usuario")); }
stmt.close();
stmt = null;
rs.close();
rs = null; When I run the query in the Query Analizer it return a correct value, but when I run mi java aplication it return a null resultSet.
what I doing bad? I need HELP!
Hi. The problem is the first call to next(), which goes to the first
row, then you do a second next() which skips it. Do this:
String sql = "select usuario "
+ " from accesos where usuario = 'patito'"
+ " and cast(DecryptByAsymKey(AsymKey_ID('EncriptadorOrbe'), "
+ " clave_E, N'Contrasena') as varchar(100)) = 'patito2'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
System.out.println("Resultado:");
while(rs.next()){
System.out.println(rs.getString("usuario"));
}
stmt.close();
stmt = null;
rs.close();
rs = null;
Oh, and close the result set first, then the statement. If you close
the statement first, it automatically closes the result set, so when
you do that, the rs.close() will throw an exception.
Joe
.
- References:
- Re: JDBC SQL2005 Read encripting fields problem
- From: Joe Weinstein
- Re: JDBC SQL2005 Read encripting fields problem
- Prev by Date: Re: JDBC SQL2005 Read encripting fields problem
- Next by Date: RE: collation SQL_EBCDIC037_CP1_CS_AS
- Previous by thread: Re: JDBC SQL2005 Read encripting fields problem
- Next by thread: RE: collation SQL_EBCDIC037_CP1_CS_AS
- Index(es):
Relevant Pages
|