-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c2b450
commit 2f0da9d
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
out | ||
target | ||
!.gitignore | ||
*.iml | ||
*.iml | ||
classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters