AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Thread synchronized JDBC ODBC Database Connection Commit

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Remi Arntzen
Guest





PostPosted: Wed Jul 13, 2005 11:33 pm    Post subject: Thread synchronized JDBC ODBC Database Connection Commit Reply with quote



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





PostPosted: Thu Jul 14, 2005 1:14 am    Post subject: Re: Thread synchronized JDBC ODBC Database Connection Commit Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.