pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedjdbc can't getResult of "select nextval (seq_name)"
2+ messages / 2 participants
[nested] [flat]
* jdbc can't getResult of "select nextval (seq_name)"
@ 1998-05-08 23:36 Felix Morley Finch <felix@crowfix.com>
1998-05-09 04:57 ` Re: [INTERFACES] jdbc can't getResult of "select nextval (seq_name)" Anil Amarakoon <anil@server.awcoldstream.com>
0 siblings, 1 reply; 2+ messages in thread
From: Felix Morley Finch @ 1998-05-08 23:36 UTC (permalink / raw)
To: pgsql-interfaces
I am a somewhat newbie with java and sql. I've run into something
that seems odd, maybe even wrong (!).
Statement seq = db.createStatement ();
seq.execute ("SELECT nextval ('cdid')");
ResultSet rs = seq.getResultSet ();
id = rs.getInt (0 + 1); <=========
The SQL works fine directly in psql. All other SQL statements seem to
work. But getInt, in this case, gets a NullPointerException. Here's
the stack dump:
Exception occurred during event dispatching:
java.lang.NullPointerException:
at postgresql.ResultSet.getString(ResultSet.java:161)
at postgresql.ResultSet.getInt(ResultSet.java:241)
at postgresql.ResultSet.getInt(ResultSet.java:569)
...
If I change the argument to 0, I get
java.sql.SQLException: Column Index out of range
I tried 'nextval' too, and got the same SQLException.
Am I doing something wrong here?
This is PostgresQL 6.3.2, Linux 2.0.33, glibc, and linux jdk 1.1.5v5
glibc. I have no problems with the Perl program which does the same
operation many places.
--
... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
Felix Finch: scarecrow repairman & rocket surgeon / felix@crowfix.com
PGP = 91 B3 94 7C E9 E8 76 2D E1 63 51 AA A0 48 89 2F ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [INTERFACES] jdbc can't getResult of "select nextval (seq_name)"
1998-05-08 23:36 jdbc can't getResult of "select nextval (seq_name)" Felix Morley Finch <felix@crowfix.com>
@ 1998-05-09 04:57 ` Anil Amarakoon <anil@server.awcoldstream.com>
0 siblings, 0 replies; 2+ messages in thread
From: Anil Amarakoon @ 1998-05-09 04:57 UTC (permalink / raw)
To: Felix Morley Finch <felix@crowfix.com>; +Cc: pgsql-interfaces
Hi!
I am no expert but this works for me.
try
{
Connection
conn=DriverManager.getConnection("jdbc:postgresql://myserver:5432/mydb","userName","password");
Statement stmt = conn.createStatement();
ResultSet rest = stmt.executeQuery("select last_value from cid ");
while (rest.next())
int myint = rest.getInt(1);
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
bla bla bla again.....
on psql if you go type select * from mysequence;
you will see what variables you can access. I am not sure it is last_value or last
value or current value.
sorry!!!
Hope this helps.
Anil
Felix Morley Finch wrote:
> I am a somewhat newbie with java and sql. I've run into something
> that seems odd, maybe even wrong (!).
>
> Statement seq = db.createStatement ();
> seq.execute ("SELECT nextval ('cdid')");
> ResultSet rs = seq.getResultSet ();
> id = rs.getInt (0 + 1); <=========
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1998-05-09 04:57 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-05-08 23:36 jdbc can't getResult of "select nextval (seq_name)" Felix Morley Finch <felix@crowfix.com>
1998-05-09 04:57 ` Anil Amarakoon <anil@server.awcoldstream.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox