Subject Re: [Firebird-Java] resultset.next() returning false
Author Catalin Florean
I did not put the entire code because it was a little to long and the
question was about the rs.next() not the try/catch, but you are right.

Catalin.

java.sql.PreparedStatement stmt = null;
java.sql.ResultSet rs = null;
try {
stmt = conn.prepareStatement("select cast(current_timestamp as
date), cnt_acte, "+
"gen_id(seq_query_log, 0),
gen_id(seq_doc_log, 0) "+
"from cnt_contor");
rs = stmt.executeQuery();
try {
if (rs.next()) {
currentDate = rs.getString(1);
cntActe = rs.getString(2);
cntQuery = rs.getString(3);
cntOpendoc = rs.getString(4);
}
}
finally {
rs.close();
rs = null;
stmt.close();
stmt = null;
}
}
catch(Exception e) {
}
finally{
if (rs != null) {
try { rs.close(); } catch (Exception e) { ; }
rs = null;
}
if (stmt != null) {
try { stmt.close(); } catch (Exception e) { ; }
stmt = null;
}
}


On 12/13/06, Steffen Heil <lists@...> wrote:
>
> Hi
>
> First, to the original question:
> > String query = "select * from USER_DETAILS where
> USR_NAME='"+usrName+"';";
> > java.sql.ResultSet rs=stmt.executeQuery(query);
> > System.out.println("the result set is:"+rs.next());
>
> Maybe there is a String converstion problem? Which character sets are you
> using? Which encodings?
> Try to prevent building queries that way. Use PreparedStatements.
> I also assume, in real code you have try-blocks to ensure closing the
> obejcts...
>
> The to the other anser...
>
> > With only one record after rs.next() you reached the end of table.
>
> No. The first next() opens just that one record.
>
> > This is a working example of a select statement on a single row table:
> >
> > stmt = conn.prepareStatement("select
> > cast(current_timestamp as date), cnt_acte, "+
> >
> > "gen_id(seq_query_log, 0), gen_id(seq_doc_log, 0) "+
> > "from cnt_contor");
> > rs = stmt.executeQuery();
> > try {
> > if (rs.next()) {
> > currentDate = rs.getString(1);
> > cntActe = rs.getString(2);
> > cntQuery = rs.getString(3);
> > cntOpendoc = rs.getString(4);
> > }
> > }
> > finally {
> > rs.close();
> > rs = null;
> > stmt.close();
> > stmt = null;
> > }
>
> This is IMHO bad code:
> .
>
>
>


[Non-text portions of this message have been removed]