I am getting
java.sql.SQLException: error occurred during batching: batch must be either executed or cleared
in the below code. I want to execute two queries.
String sql_query="insert into m_status values(20,'test');select * from m_user";
String query1 = sql_query.toUpperCase();
String[] results = query1.split(";");
stmt = conn1.createStatement();
conn1.setAutoCommit(false);
for (int i = 0; i < results.length; i++) {
if(results[i].startsWith("SELECT")) {
rs1 = stmt.executeQuery(results[i]);
}
else if(results[i].startsWith("INSERT")){
stmt.addBatch(results[i]);
}
}
int [] updateCounts = stmt.executeBatch();
conn1.commit();
if (rs1 != null)
rs1.close();
if (stmt != null)
stmt.close();
if (conn1 != null)
conn1.close();