• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Pooling & ResultSet behavior

 
tomasz brymora
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class that interacts with the McKoi DB: saves, retrieves and
deletes rows from.
I've tested the saving part: works fine without a problem.
Problem show's up when I try RETRIEVE (print to screen) DELETE a wor
and
RETRIEVE again. What was ment to
get deleted still shows up. It disapears from the display however the
second
time i cycle through the program.

I'm utilizing connection pooling code from Javaexchange.com, keeping 6
connections in the pool (if that could eve be relevant to the case).

HERE'S RETRIEVING PART:

public ResultSet retrieveAllStudents(){
ResultSet result2 = null;
Statement s2 = null;
try{
Connection c = myBroker.getConnection();
s2 = c.createStatement();
result2 = s2.executeQuery(
" SELECT student_ID, name, student_psw FROM Student"
);
myBroker.freeConnection(c);
}
catch(Exception e2){}

return result2;
}

HERE'S THE DELETING PART:

public void deleteStudent(String studentName){
Statement s3 = null;
try{
Connection c = myBroker.getConnection();
s3 = c.createStatement();
s3.executeQuery(
"DELETE FROM Student WHERE name = '" + studentName +"'"
);
myBroker.freeConnection(c);
}
catch(Exception e7){}

}

so, I've tested deleteStudent() by itself and it deletes fine.
Somehow when I call RETRIEVE DELETE RETRIEVE the changes don't show
up on
the second RETRIEVE.
I'm using NetBeans 3.6 for it
 
Albert Gan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, there could be 2 possibilities.
First, your statement.executeQuery("DELETE asdf FROM asdf") wont work. use statement.executeUpdate(String) instead. That is supposed to be your problem.
Second, the Connection object from your broker could be in a transaction mode, in which Connection.setAutoCommit(false). In that case, after executing updates, you should Connection.commit().

good luck to you ^^
 
tomasz brymora
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow! thank you so much! when starting out there are so many possible leads to follow, one could just go nuts sometimes. i'll try that out and see.
thanks :>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic