help pls with jdbc-mysql problem
From: matt (ty_li_at_yahoo.com)
Date: 11/12/04
- Next message: Hal Rosser: "Re: Pass Values to Java"
- Previous message: Ryan Johnson: "Pass Values to Java"
- Next in thread: MishGun: "Re: help pls with jdbc-mysql problem"
- Reply: MishGun: "Re: help pls with jdbc-mysql problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Nov 2004 15:31:11 -0800
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
- Next message: Hal Rosser: "Re: Pass Values to Java"
- Previous message: Ryan Johnson: "Pass Values to Java"
- Next in thread: MishGun: "Re: help pls with jdbc-mysql problem"
- Reply: MishGun: "Re: help pls with jdbc-mysql problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|