I want to insert a row in a table in Oracle SQL Developer. I have a set of Strings, String name
, String address
, and String contact
.
It won't work if I use this code:
Connection conn = null;
Statement stmt = null;
String URL = "jdbc:oracle:thin:mariel@//localhost:1521/XEXDB";
String USER = "mariel";
String PASS = "1234";
String name = "a", address = "a", contact="a";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
try {
conn = DriverManager.getConnection(URL, USER, PASS);
stmt = conn.createStatement();
String sql = "INSERT INTO CUSTOMER" +
"VALUES(CustNumSeq.NEXTVAL, name, address, contact)";
stmt.executeUpdate(sql);
}
catch (SQLException ex) {
Logger.getLogger(FinishTransaction.class.getName()).log(Level.SEVERE, null, ex);
}
}
catch(ClassNotFoundException ex) {
System.out.println("Error: unable to load driver class!");
System.exit(1);
}
finally{
try{
if(stmt!=null)
stmt.close();
}
catch(SQLException se2){
}
try{
if(conn!=null)
conn.close();
}
catch(SQLException se){
se.printStackTrace();
}
}