hi guys ,
i have a problem getting the sequence number. i have a table named customer .. where i have want to auto generate the customer id .. so i have used sequence on customer id .. now if i want to insert a new customer from my java program ..first i shud get the sequence number .. how do i get it .. i tried using
int cust_id = statement.executeUpdate("select cust_sequence from dual",RETURN_GENERATED_KEYS );
looks like it isnt working ... although when i print the current value from sql*plus it is incrementing the sequence number ..
OR simply this code is not working .whatz wrong with this .. can anybody pls point out
import java.sql.*;
import java.sql.Statement.*;
public class ConnectionJdbc {
public static Connection con = null;
public Connection connect()throws SQLException{
String dbURI = "jdbc

racle:thin:@host:1521:mydb";
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
con = DriverManager.getConnection(dbURI,"SCOTT","TIGER");
return con;
}
public static void main(String [] args)throws Exception{
int cust_id = 0;
String title = "ms";
String firstname ="Akshatha";
String lastname = "Nayak";
Statement stmt = null;
ResultSet rs = null;
ConnectionJdbc conjdbc = new ConnectionJdbc();
try {
Connection con = conjdbc.connect();
stmt = con.createStatement();
cust_id = stmt.executeUpdate("SELECT CUST_SEQUENCE.NEXTVAL FROM DUAL");
String SQLCommand = "INSERT INTO CUSTOMER (cust_id,title,firstname,lastname) VALUES"+ "("+ cust_id + ",'"+ title +"',"+
"'"+ firstname + "'," + "'" + lastname + "')" ;
rs = stmt.executeUpdate(SQLCommand);
} finally {
// Close connection
if (con != null) {
try {
con.close();
} catch (SQLException ex) {
System.out.println("Error in closing Conection");
ex.printStackTrace();
}
}
}
}
}