samblake
asked on
Java and currval
I'm having trouble getting the currval function to work from a Java program (or from Postgres at all). I want to get the value of addressid in the table taddress. The best I seem to be able to come up with is 'SELECT currval(taddress.addressid )'. However this gives me the error 'ERROR: relation "1" does not exist' or whatever the number should be. I've tried lots of variations but can't seem to work it out. What am I doing wrong? Thanks.
-Sam
-Sam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
absong is correct in his contribution. Share the points with absong.
import java.sql.*;
class PostgreSQLTest {
public static void main (String[] args) {
try {
String url = "jdbc:postgresql://localho
Connection con = DriverManager.getConnectio
Statement stm = con.createStatement();
stm.setQueryTimeout(10);
ResultSet rs = stm.executeQuery("select addressid from taddress");
rs.next();
System.out.println(rs.getS
}
catch (SQLException e) {
System.out.println("Except
System.out.println(e.toStr
}
}
}
export CLASSPATH=.:$JAVA_HOME/jre
javac PostgreSQLTest.java
java -Djdbc.drivers=org.postgre
Hello Postgres Java World !