Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resource usage

 
Mark Leong
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would appreciate if somebody could tell me if the follow code would use up server resouces excessively if there are 10 hits to the servlet per second.
How to improve the code?
Thanks.
------------------Code excerpt------------------------

//get db connection
Connection connection = null;
try {
connection = connectionPool.getConnection();
Statement statement = connection.createStatement();

QueryStatement = "select * from table1..............";
ResultSet RSResult = statement.executeQuery(QueryStatement);

while (RSResult.next()){
//perform some action..........
}
RSResult.close();
QueryStatement = "delete from table1...........";
int DeleteResult = statement.executeUpdate(QueryStatement);
QueryStatement = "Update table2...............";
int Update = statement.executeUpdate(QueryStatement);
QueryStatement = "delete from table3............";
int Delete = statement.executeUpdate(QueryStatement);

connection.close();
connectionPool.free(connection);

}
finally {
try {
if (connection != null ) {
//close the connection no matter what
connectionPool.free(connection);
connection.close();
}
}
catch (SQLException sqle){
System.err.println(sqle.getMessage());
}
}
} catch(SQLException sqle) {
System.err.println("Error connecting: " + sqle);
}

----------end of code excerpt ---------------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic