Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2004

Tip: Looking for answers? Try searching our database.

help pls with jdbc-mysql problem

Thread view: 
matt - 11 Nov 2004 23:31 GMT
Thanks  in advance for any advice!!!

Mysql jdbc driver problem

I query a mysql db with JDBC connector. The program check DB every 10
second. At each query, it checks whether new rows are written into DB
table. If yes, fetch the new
Rows and print on stdout.
The problem is:
1.    there is a 2-5 minutes time lag between the time the row is written
and the time the row is printed in Java program.
2.    some rows get duplicated. It means, one query will sometimes show
some rows which are already displayed in previous query.
3.    some rows get dropped.

The driver I used is:
MySQL Connector/J 3.0.7 Stable (formerly MM.MySQL)
MySQL AB's JDBC Driver for MySQL
Copyright (c) 2002 MySQL AB
Algorithm of code

 //establish connection
 //make sql string
While(true)
{

             rs = stmt.query(sqlstring)
            //directly go to the next row from the last row read in
last query
              rs.absolute(prevLastRow+1);
           
            //loop to retrieve data in the ResultSet rs
            while (rs.next()) {
                                     …..
                                   }
                               //make cursor point to last row
             rs.last();
               //store a value in last row
           lastCid=rs.getString(2);//update last cid
               //update the value of prevLastRow
           prevLastRow=rs.getRow();
                rs.close();
         
                   //sleep for 120 second
     
         Thread.sleep(readDBFrequency);
} //outer loop
MishGun - 12 Nov 2004 05:34 GMT
Hello,
Another way is:

...
//establish connection
while (true) {
  rs = stmt.query("SELECT * FROM table WHERE cid > " + lastCid);      
  while (rs.next) {
       System.out.println(rs.getString()); // print new row
       lastCid = rs.getString(2); //update last row
  }
  //sleep
}
...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.