Re: st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valor"); - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valor");
Date
Msg-id Pine.LNX.4.33.0302030942380.9706-100000@leary.csoft.net
Whole thread Raw
In response to st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valor");  (Elielson Fontanezi <ElielsonF@prodam.sp.gov.br>)
List 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 I�ve
> created so far,
> but with this sequence no data comes from.
>     I am uncapable of guessing what can be.
>
>     I�d 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@prodam.sp.gov.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
>


pgsql-jdbc by date:

Previous
From: pginfo
Date:
Subject: Re: Sun J2EE server (default with J2EE package) + PostgreSQL
Next
From: J M Okomba
Date:
Subject: Re: st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valo