Subject | Re: Query returning row when it shouldn't... |
---|---|
Author | time_lord2004 |
Post date | 2004-05-31T05:24:29Z |
--- In firebird-support@yahoogroups.com, Phil <time_lord@h...> wrote:
"select PK_SN from MYTABLE order by PK_SN desc"
If there are no rows then rs.next() returns false (good!).
If there ARE rows then in the first one returned PK_SN is the max
value (because of the order-by & descending). But that's a pretty ugly
solution...
> Hi, I'm a new Firebird user, using Firebird-1.5.0.4306-Win32 andstarts it
> Firebird-JDBC-SQL-1.5.0Beta3JDK_1.4.
>
> I have a new database , no data in it yet. When my application
> looks for a value in the database, returning it if found, i.e somethingproblem
> like:
>
> ...
> java.sql.Statement s = myConnection.createStatement();
> ResultSet rs = s.executeQuery("select max(PK_SN) from MYTABLE");
> if (rs.next())
> // Then the row exists - return the value:
> return rs.getInt("PK_SN");
>
> However an exception occurs on the last line:
> "org.firebirdsql.jdbc.FBSQLException: Column name PK_SN not found in
> result set"
> This in itself is not a suprise because there are no rows... the
> is that rs.next() should return false (indicating that there is not aI forgot - one way around this is to do:
> 'next' row).
>
> Can anyone confirm that this is a bug and suggest the 'firebird' way of
> doing it? (This sort of thing works properly with SQLserver )
>
> TIA
"select PK_SN from MYTABLE order by PK_SN desc"
If there are no rows then rs.next() returns false (good!).
If there ARE rows then in the first one returned PK_SN is the max
value (because of the order-by & descending). But that's a pretty ugly
solution...