-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBWriter.java
33 lines (24 loc) · 1.85 KB
/
DBWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class DBWriter {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/temp", "root", "password");
conn.setAutoCommit(false);
long start = System.nanoTime();
int numMessages = 1000;
for(int i = 0; i < numMessages; i++){
PreparedStatement stmt = conn.prepareStatement("insert into commslog values (?, ?)");
stmt.setString(1, "" + System.currentTimeMillis());
// 1000 chars
stmt.setString(2, "some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, some really long string, ");
stmt.executeUpdate();
//commit and close
stmt.close();
conn.commit();
}
System.out.println("avg write " + (((System.nanoTime()-start)/1000000.0)/numMessages) + " ms");
conn.close();
}
}