-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0, 1.3.1
-
rc1
-
x86
-
windows_nt, windows_2000
Name: boT120536 Date: 01/25/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
The attached application takes two arguments, the first is a url of the form
jdbc:odbc:MyDSN the second is the size of batch to use (0 implies don't use
batching). My database server is MS SQLServer 7 with the standard ODBC driver.
If the batch parameter is zero, the expected result occurs (a table containing
the tuples i,-i for i 1 to 50). If the batch parameter is any positive value
(e.g. 10), then the table content is junk:
1986087519 1986087519
1970495329 1970495329
1684692846 1684692846
1868522338 1868522338
1600348772 1600348772
1667392586 1667392586
1667392591 1667392591
1702389087 1702389087
1702131043 1702131043
3551552 3551552
-11 -11
-12 -12
-13 -13
-14 -14
-15 -15
-16 -16
-17 -17
etc
The application:
package test.jdbc;
import java.sql.*;
class TestBatchUpdate
{
public static void main(String[] args)
{
String driver = System.getProperty
("driver", "sun.jdbc.odbc.JdbcOdbcDriver");
try
{
Class.forName(driver);
Connection conn = DriverManager.getConnection(args[0]);
createTable(conn);
int m = args.length > 1 ? Integer.parseInt(args[1]) :
10;
if (m == 0)
System.out.println("No batching");
else
System.out.println("Batch size is "+m);
fillTable(conn, m);
readTable(conn);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private static void createTable(Connection conn) throws SQLException
{
Statement s = conn.createStatement();
try
{
s.executeUpdate("drop table BatchTable");
}
catch (SQLException ex)
{
}
s.executeUpdate("create table BatchTable (row int, rv int)");
s.close();
}
private static void fillTable(Connection conn, int batchSize) throws
SQLException
{
PreparedStatement s = conn.prepareStatement("insert BatchTable
(row, rv) values(?,?)");
int count = 0;
for (int i=1; i<=50; i++)
{
s.setInt(1, i);
s.setInt(2, -i);
if (batchSize == 0)
s.executeUpdate();
else
{
s.addBatch();
count++;
if (count == batchSize)
{
s.executeBatch();
count = 0;
}
}
}
if (count > 0)
s.executeBatch();
s.close();
}
private static void readTable(Connection conn) throws SQLException
{
Statement s = conn.createStatement();
ResultSet results = s.executeQuery("select row,rv from
BatchTable");
int n=0;
while (results.next())
{
System.out.print(results.getInt(1));
System.out.print(" ");
System.out.println(results.getInt(2));
n++;
}
System.out.println(n+" Rows");
results.close();
s.close();
}
}
(Review ID: 114709)
======================================================================