aspose file tools*
The moose likes JDBC and the fly likes Accessing One table with multiple Threads and Inserting Values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Accessing One table with multiple Threads and Inserting Values" Watch "Accessing One table with multiple Threads and Inserting Values" New topic
Author

Accessing One table with multiple Threads and Inserting Values

Guneet Aulakh
Greenhorn

Joined: Dec 16, 2004
Posts: 3
Hello fellow members!

I am trying to save values to a table in Access, I have 3 threads that update this single table, but it seems to be overwriting the values in the table. Could any of you please guide me on what I am dooing wrong. The code is as follows:

Here are the 3 threads:


Here is the part from the run() where I call the JDBC:


Here is the part where we Update and Read the DB:



Here is the output

Thread : Thread-0
Data from Init_Cell: 0
Data from Final_Cell: 18

Thread : Thread-1
Data from Init_Cell: 4
Data from Final_Cell: 13

Thread : Thread-2
Data from Init_Cell: 7
Data from Final_Cell: 14

When I check the Table in the DB all is see is the last entry of 7 and 14, while the rest are missing!

Your suggestions and support are much appreciated.

Guneet

[edited to disable smilies]
[ December 27, 2004: Message edited by: Jeanne Boyarsky ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30352
    
150

Guneet,
Welcome to JavaRanch!

What do you expect to see? Each time the update statement runs, it overwrites the previous values in the table. So after the threads are finished, you would see the results of whatever thread happened to run last.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Guneet Aulakh
Greenhorn

Joined: Dec 16, 2004
Posts: 3
Please forgive my ignorance, but should I be trying Insert here, rather then update. It is 12 in the night! I will try with the insert, first thing in the morning, and post a reply here.

Thanks

Guneet
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30352
    
150

Guneet,
Yes! It should work with insert.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing One table with multiple Threads and Inserting Values