Skip to content

Commit

Permalink
#Batch Insert test.
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowBPF2 committed May 7, 2018
1 parent 4c2b450 commit 2f0da9d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
out
target
!.gitignore
*.iml
*.iml
classes
48 changes: 48 additions & 0 deletions src/test/java/jdbc/BatchInsert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class BatchInsert {
public static void main(String[] args) throws SQLException {

Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/rainbow?user=root&password=jack_bai?useSSL=false");

conn.setAutoCommit(false);
PreparedStatement ps = conn.prepareStatement("insert into userinfo (name, salary,comment, password,email) values(?,?,?,?,?)");

for (int i = 0; i < 20980; i++) {
ps.setString(1, "name" + i);
ps.setDouble(2, i);
ps.setString(3, "comment" + i);
ps.setString(4, "pwd" + i);
ps.setString(5, "[email protected]");
ps.addBatch();

if (i % 100 == 0) {
ps.executeBatch();
ps.clearParameters();
System.out.println("Executed once!");

}
}
ps.executeBatch();

conn.commit();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
conn.close();

}


}
}
2 changes: 0 additions & 2 deletions threadLearn/src/jvm/GCTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package jvm;

import com.sun.glass.ui.Size;

/**
* Created by pengfei on 2017/9/6.
*/
Expand Down
6 changes: 5 additions & 1 deletion threadLearn/src/jvm/UnSafeMem.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
package jvm;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
*/
/**
* Created by pengfei on 2017/9/6.
*/
*//*
public class UnSafeMem {
private static final int _1M=1024*1024;
Expand All @@ -21,3 +24,4 @@ public static void main(String[] args) throws IllegalAccessException {
}
}
*/

0 comments on commit 2f0da9d

Please sign in to comment.