I have the following that doesnt seem to work. The custID field i haven't specified in the prepare statement (because it's an AUTO_INCREMENT value , but for some reason it won't work without it. Nothing is added to the table when the method is completely run.
int rows = 0;
Connection conn = getConnection();
PreparedStatement pstmt = null;
try{
pstmt = conn.prepareStatement(
"insert into Customers values(" +
"?," + //customername
);
pstmt.setString(1, customerBean.getCustomerName());
}
catch (SQLException se)
{
rollback(conn);
System.out.println(msg);
System.out.println(se);
throw new Exception(se);
}
| Field | Type | Null | Key | Default | Extra |
-------------------------
-----------
-------------------------+
| CUST_ID | int(11) | NO | PRI | NULL | auto_increment |
| CUST_NAME | varchar(100) | YES | | NULL | |
Any ideas? I want a proper way of forumlating a query using a prepared statement and using the AUTO_INCREMENT value so that when a new row is added the cust_Id field is incremented.
Another question, why is the SQLException not being caught? I have another method which gets all the rows from a table, if i change the prepared statement to an invalid table then it gives me an exception. I was previously using Oracle, SQLException was being caught when a duplicate entry was added.