Mysql java conectivty problem - No operations allowed after connection clos
681725Jul 20 2008 — edited Jan 20 2015I use jdbc to connect java desktop application with mysql database. I use mysql-connector-java-5.1.5-bin.jar.
I use the code down to connect to db. My Idea is to open connection one and with this connection to send more than one statements. The application connects to database but after few statements it throws this exception:
"No operations allowed after connection closed."
I do not close connection anywhere. What happens here ?
Is it bug in the driver?
I think it might be something with threads. If there is more than one thread that wants to connect with the database but there is only one opened connection it could be a problem.
If you have some ideas please share with me ...
10x all
public void DbConnect() {
try
{
String userName = "user";
String password = "parola";
String url = "jdbc:mysql://localhost:3306/db";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection (url, userName, password);
if( ! conn.isValid(10)){
this.dispose();
}
catch (Exception e)
{
this.dispose();
}
}
this metod is in public void run() { }
on button clicked this code is in the method
try{
s = conn.createStatement();
// s is public member varible
// r is public member varible and its type is ResultSet
r =s.executeQuery("SELECT * FROM table" );
while (r.next()) {
String temp= r.getString("column_name");
jTextField1.setText(temp);
}
r.close();
s.close();
}
catch (Exception e)
{
jTextField1.setText("problem");
e.printStackTrace();
}
finally {
try{
s.close();
r.close();
}catch(Exception e){
}
}