st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valor");

From: Elielson Fontanezi <ElielsonF(at)prodam(dot)sp(dot)gov(dot)br>
To: pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: st.executeQuery("SELECT NEXTVAL('seq_suporte') AS valor");
Date: 2003-02-03 13:12:51
Message-ID: A799F7647794D311924A005004ACEA9709699311@cprodamibs249.prodam
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

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(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. |
+--------------------------------------------------------+

Responses

Browse pgsql-general by date

  From Date Subject
Next Message paul butler 2003-02-03 13:47:05 Re: Creation of VIEWS not working....
Previous Message Thomas Adam 2003-02-03 12:59:33 Creation of VIEWS not working....

Browse pgsql-jdbc by date

  From Date Subject
Next Message pginfo 2003-02-03 13:37:42 Re: Sun J2EE server (default with J2EE package) + PostgreSQL
Previous Message Bruce Momjian 2003-02-03 11:41:14 Re: DatabaseMetaData oddities