|
Consult a mysql data concurrency, causing inaccurate data statistics, urgent
I used jsp + mysql to make a website statistics. After inserting statistics code into your website, I counted your total browsing IP data, and the total number of browsing IPs per day, and the total number of browsing IPs per hour per day.
But after I found the statistics, the numbers added per hour, I am sorry for the daily data, the data added for each day, not the total number of browsing IPs, I use the mysql database, and I use the mysql MyISAM format.
My program code is as follows:
Is it that mysql has a large amount of concurrent data at the same time, or is there any reason how to analyze this data can be synchronized, the statistics of the various tables of the data can be consistent with each other, and accurate and consistent with each other
I have also built three tables, one is the user table, which has a total volume of clicks;
The other is a daily table.
Another is the hour meter, which counts the hourly click-out scale for each user.
// Statistical total click-through volume
dbc.prepareStatement (
"update users set outscore = outscore +? where username =?");
dbc.setDouble (1, unitscoredouble);
dbc.setString (2, outname);
dbc.executeUpdate ();
// Statistics of the daily order volume
dbc.prepareStatement (
"select username from userdayhistory where username =? and dotyearmonth =? and dotday =?");
dbc.setString (1, outname);
dbc.setInt (2, yyyyMM);
dbc.setInt (3, d);
rs = dbc.executeQuery ();
if (rs.next ()) {
dbc.prepareStatement (
"update userdayhistory set outscore = outscore +? where username =? and dotyearmonth =? and dotday =?");
dbc.setDouble (1, unitscoredouble);
dbc.setString (2, outname);
dbc.setInt (3, yyyyMM);
dbc.setInt (4, d);
dbc.executeUpdate ();
}
else {
try {
dbc.prepareStatement ("INSERT INTO userdayhistory (username, outscore, putscore, dotyearmonth, dotday) VALUES (?,?,?,?,?)");
dbc.setString (1, outname);
dbc.setDouble (2, unitscoredouble);
dbc.setInt (3, 0);
dbc.setInt (4, yyyyMM);
dbc.setInt (5, d);
dbc.executeUpdate ();
}
catch (SQLException ex7) {
System.out.println ("494");
}
}
// Statistical hourly output
dbc.prepareStatement (
"select username from userhourhistory where username =? and dotyearmonthday =? and dothour =?");
dbc.setString (1, outname);
dbc.setInt (2, yyyyMMdd);
dbc.setInt (3, H);
rs = dbc.executeQuery ();
if (rs.next ()) {
dbc.prepareStatement (
"update userhourhistory set outscore = outscore +? where username =? and dotyearmonthday =? and dothour =?");
dbc.setDouble (1, unitscoredouble);
dbc.setString (2, outname);
dbc.setInt (3, yyyyMMdd);
dbc.setInt (4, H);
dbc.executeUpdate ();
}
else {
try {
dbc.prepareStatement ("INSERT INTO userhourhistory (username, outscore, putscore, dotyearmonthday, dothour) VALUES (?,?,?,?,?)");
dbc.setString (1, outname);
dbc.setDouble (2, unitscoredouble);
dbc.setInt (3, 0);
dbc.setInt (4, yyyyMMdd);
dbc.setInt (5, H);
dbc.executeUpdate ();
}
catch (SQLException ex11) {
System.out.println ("9994");
}
} |
|