From: | Kris Jurka <books(at)ejurka(dot)com> |
---|---|
To: | Elielson Fontanezi <ElielsonF(at)prodam(dot)sp(dot)gov(dot)br> |
Cc: | pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: [JDBC] st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valor"); |
Date: | 2003-02-03 14:43:12 |
Message-ID: | Pine.LNX.4.33.0302030942380.9706-100000@leary.csoft.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-jdbc |
You are not doing a rs.next() before rs.getInt().
Kris Jurka
On Mon, 3 Feb 2003, Elielson Fontanezi wrote:
> Hi Folks!
>
> I need some help.
> See this code parcel:
>
> ...
> ...
> ResultSet rs =
> st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valor");
> ...
> ...
>
> It produces: java.lang.NullPointerException
>
> What is problem?
> I am used to do SELECT commands like this with any table Ive
> created so far,
> but with this sequence no data comes from.
> I am uncapable of guessing what can be.
>
> Id appreciate suggestions.
>
> Below there is a short program that reproduces this case.
>
> Thanks!
>
> -----------------------------------------------------------------
> import java.sql.*;
>
> class pgdbping
> {
> public static void main(String args[])
> {
> try
> {
> Class.forName("org.postgresql.Driver");
>
> Connection con = DriverManager.getConnection(
> "jdbc:postgresql://10.10.96.147:5432/suporte",
> "suporte", "suporte");
>
> System.out.println("Connection successful!!");
>
> Statement st = con.createStatement();
>
> ResultSet rs = st.executeQuery(
> "SELECT NEXTVAL('seq_suporte') AS valor");
>
> int novoCodigoSuporte =
> rs.getInt("valor");
>
> st.close();
> con.close();
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
> }
> }
>
>
> +--------------------------------------------------------+
> | _ Elielson Fontanezi (elielsonf(at)prodam(dot)sp(dot)gov(dot)br) |
> | v PRODAM - VSE Department +55 11 5080-9283 |
> | /(_)\ May your trails be crooked, winding, lonesome, |
> | ^ ^ dangerous, leading to the most amazing view. |
> | May your mountains rise into and above the clouds. |
> +--------------------------------------------------------+
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
From | Date | Subject | |
---|---|---|---|
Next Message | Nigel J. Andrews | 2003-02-03 14:49:39 | Re: DBI driver and transactions |
Previous Message | Simon Mitchell | 2003-02-03 14:31:42 | Re: Creation of VIEWS not working.... |
From | Date | Subject | |
---|---|---|---|
Next Message | J M Okomba | 2003-02-03 14:52:04 | Re: st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valo |
Previous Message | pginfo | 2003-02-03 13:37:42 | Re: Sun J2EE server (default with J2EE package) + PostgreSQL |