 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Remi Arntzen Guest
|
Posted: Wed Jul 13, 2005 11:33 pm Post subject: Thread synchronized JDBC ODBC Database Connection Commit |
|
|
Here is a short version of my class
class CLASSNAME {
static LOCK = new Object();
Connection con = //initalized elsewhere
public void countMethod() {
synchronized (LOCK) {
boolean isExist = //Check database if entry already exists
(JDBC-ODBC Microsoft Access)
if (isExist) {
//UPDATE ENTRY
} else {
//INSERT ENTRY
/*
* I call statement.close(); when done with all
statements
*/
//javax.swing.JOptionPane.showMessageDialog(null,
"inserting" + Thread.currentThread().getId());
}
con.commit();
}
}//END OF METHOD
}//END OF CLASS
My problem is that "UPDATE ENTRY" does not seem to be "commit"ed in the
database when another thread calls "countMethod()", because "INSERT
ENTRY" is called twice.
However this problem is corrected when I uncomment the
"javax.swing.[...]showMessage[...]" line. So I belive that the
underlying database needs a little time to update it self, even if
commit returns successfully.
I woundered if anyone might have an explination as to what this is
caused by, and how to get around it.
If it matters this class is a filter in a j2ee server.
|
|
| Back to top |
|
 |
Remi Arntzen Guest
|
Posted: Thu Jul 14, 2005 1:14 am Post subject: Re: Thread synchronized JDBC ODBC Database Connection Commit |
|
|
I guess this would be important
boolean isExist = //Check database if entry already exists
//is
ResultSet aResultSet = statement.executeQuery("[SQL]");
boolean isExist = aResultSet.next();
statement.close();
any tips will be appreciated.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|