Skip to content

Commit 2f0da9d

Browse files
committed
#Batch Insert test.
1 parent 4c2b450 commit 2f0da9d

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
out
33
target
44
!.gitignore
5-
*.iml
5+
*.iml
6+
classes

src/test/java/jdbc/BatchInsert.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package jdbc;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.PreparedStatement;
6+
import java.sql.SQLException;
7+
8+
public class BatchInsert {
9+
public static void main(String[] args) throws SQLException {
10+
11+
Connection conn = null;
12+
try {
13+
Class.forName("com.mysql.jdbc.Driver");
14+
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/rainbow?user=root&password=jack_bai?useSSL=false");
15+
16+
conn.setAutoCommit(false);
17+
PreparedStatement ps = conn.prepareStatement("insert into userinfo (name, salary,comment, password,email) values(?,?,?,?,?)");
18+
19+
for (int i = 0; i < 20980; i++) {
20+
ps.setString(1, "name" + i);
21+
ps.setDouble(2, i);
22+
ps.setString(3, "comment" + i);
23+
ps.setString(4, "pwd" + i);
24+
ps.setString(5, "abc@126.com");
25+
ps.addBatch();
26+
27+
if (i % 100 == 0) {
28+
ps.executeBatch();
29+
ps.clearParameters();
30+
System.out.println("Executed once!");
31+
32+
}
33+
}
34+
ps.executeBatch();
35+
36+
conn.commit();
37+
} catch (SQLException e) {
38+
e.printStackTrace();
39+
} catch (ClassNotFoundException e) {
40+
e.printStackTrace();
41+
} finally {
42+
conn.close();
43+
44+
}
45+
46+
47+
}
48+
}

threadLearn/src/jvm/GCTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package jvm;
22

3-
import com.sun.glass.ui.Size;
4-
53
/**
64
* Created by pengfei on 2017/9/6.
75
*/

threadLearn/src/jvm/UnSafeMem.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
/*
12
package jvm;
23
34
import sun.misc.Unsafe;
45
56
import java.lang.reflect.Field;
67
8+
*/
79
/**
810
* Created by pengfei on 2017/9/6.
9-
*/
11+
*//*
12+
1013
public class UnSafeMem {
1114
private static final int _1M=1024*1024;
1215
@@ -21,3 +24,4 @@ public static void main(String[] args) throws IllegalAccessException {
2124
2225
}
2326
}
27+
*/

0 commit comments

Comments
 (0)