Subject RE: [Firebird-Java] resultset.next() returning false
Author Steffen Heil
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:
1. Incluse prepareStatemend and executeQuery in the try block.
2. Assure stmt.close() is called, even if rs.close() failed. (Could happen
if executeQuery() failed.

Regads,
Steffen


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