Batch Updates with Prepared Statements - ***NEED HELP***
843859Nov 12 2008 — edited Nov 20 2014I am working on this lab assignment for my Java class at school. The lab is instructing me to insert 7 customers into a table using a prepared statement and batch updates. I did 2 customers to begin with but only 1 of the prepared statements executes in the batch. Help would be much appreciated.
Here is a sample code of my insert function for the database:
The insert SQL update is: INSERT INTO CUSTOMER(custId, custName, custLocation) VALUES(?,?,?)
private void insert()
{
try
{
pstmt = conn.prepareStatement(insertStmt);
pstmt.setInt(1, 1000);
pstmt.setString(2, "Bob Sheppard");
pstmt.setString(3, "St. Louis, MO");
pstmt.addBatch();
pstmt.setInt(1, 1001);
pstmt.setString(2, "Jared Butcher");
pstmt.setString(3, "St. Louis, MO");
pstmt.addBatch();
int[] insertCounts = pstmt.executeBatch();
System.out.println("Insert Complete");
}
catch(SQLException ex)
{
ex.printStackTrace();
}
}