SilverStray
Programmer
Somewhere between the loop, I encounter an error which says: java.sql.SQLException: Connection is closed.
What is the proper way of using PreparedStatement and Connection when inside a loop? I have the following similar code which results on a Connection Closed problem. I wonder what could be wrong in this...
---
Connection conn = this.jdbcFactory.getConnection();
String val = "";
String sqlString = "";
for(int m=0; m<array1.length; m++){
val = array1[m];
sqlString = "UPDATE TABLE1 "
"SET COL1 = '" + val + "'";
PreparedStatement ps = conn.prepareStatement(sqlString);
try{
ps.executeUpdate();
ps.close();
} catch (SQLException e){
ps.close();
conn.close();
}
conn.close();
}
Thanks in advance!
What is the proper way of using PreparedStatement and Connection when inside a loop? I have the following similar code which results on a Connection Closed problem. I wonder what could be wrong in this...
---
Connection conn = this.jdbcFactory.getConnection();
String val = "";
String sqlString = "";
for(int m=0; m<array1.length; m++){
val = array1[m];
sqlString = "UPDATE TABLE1 "
"SET COL1 = '" + val + "'";
PreparedStatement ps = conn.prepareStatement(sqlString);
try{
ps.executeUpdate();
ps.close();
} catch (SQLException e){
ps.close();
conn.close();
}
conn.close();
}
Thanks in advance!