jdbc batch
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestBatch {
public static void main(String[] args) throws Exception {
TestBatch tb=new TestBatch();
Connection conn=tb.getConn();
conn.setAutoCommit(false);
stmt.addBatch("insert into student(name,sex,grade) values('binge','m','2008811236')");
//stmt.addBatch("delete from student where name='dandan4'");
stmt.addBatch("delete from student where name='dandan4'");
stmt.executeBatch();
conn.commit();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next()){
System.out.println("Row: "+rs.getRow()+"\tId: "+rs.getInt(1)+"\tName: "+rs.getString(2)
+"\tSex: "+rs.getString(3)+"\tGrade: "+rs.getString(4));
}
rs.close();
stmt.close();
conn.close();
}
public Connection getConn() {
Connection conn=null;
String url="jdbc:mysql://127.0.0.1/dandan?user=root&password=dada";
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
conn=DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestBatch {
public static void main(String[] args) throws Exception {
TestBatch tb=new TestBatch();
Connection conn=tb.getConn();
conn.setAutoCommit(false);
Statement stmt=conn.createStatement();
//將給定的 SQL 命令新增到此 Statement
物件的當前命令列表中。
stmt.addBatch("insert into student(name,sex,grade) values('binge','m','2008811236')");
//stmt.addBatch("delete from student where name='dandan4'");
stmt.addBatch("delete from student where name='dandan4'");
stmt.executeBatch();
conn.commit();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next()){
System.out.println("Row: "+rs.getRow()+"\tId: "+rs.getInt(1)+"\tName: "+rs.getString(2)
+"\tSex: "+rs.getString(3)+"\tGrade: "+rs.getString(4));
}
rs.close();
stmt.close();
conn.close();
}
public Connection getConn() {
Connection conn=null;
String url="jdbc:mysql://127.0.0.1/dandan?user=root&password=dada";
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
conn=DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}
相關文章
- 聊聊jdbc的batch操作JDBCBAT
- JDBC優化之Batch、FetchJDBC優化BAT
- 【BATCH】BATCH-CopyBAT
- 解毒batch normalizationBATORM
- TSM BATCH模式BAT模式
- 陪你解讀Spring Batch(一)Spring Batch介紹SpringBAT
- 5 Fansites Q & A BatchBAT
- Batch Scripting TutorialBAT
- 陪你解讀Spring Batch(二)帶你入手Spring BatchSpringBAT
- Batch入門教程(2)BAT
- Learning with Mini-BatchBAT
- Spring Batch專題SpringBAT
- nuget packages batch installPackageBAT
- Using svn in CLI with BatchBAT
- SAP 批次管理(Batch management)BAT
- Spring Batch 簡介SpringBAT
- 神經網路常見引數解釋:epoch、batch、batch size、step、iteration神經網路BAT
- TensorFlow實現Batch NormalizationBATORM
- 深度學習中 Batch Normalization深度學習BATORM
- batch、epoch、iteration的區別BAT
- tensorflow使用BN—Batch NormalizationBATORM
- MySQL使用Batch批量處理MySqlBAT
- Use windows batch script to create menuWindowsBAT
- JDBCJDBC
- codeurjc/spring-mail-batch:使用Spring Batch批次傳送電子郵件SpringAIBAT
- Spring Boot整合Spring BatchSpring BootBAT
- batch normalization學習理解筆記BATORM筆記
- SAP Batch Derivation功能初探之二BAT
- SAP Batch Derivation功能初探之一BAT
- flink batch dataset 的基本操作BAT
- 【BATCH】BOESDK-Upload Deploy ToolBAT
- How to use "for/" batch command in Dos extentionBAT
- JDBC學習1:詳解JDBC使用JDBC
- JavaWeb——JDBCJavaWebJDBC
- JDBC概述JDBC
- jdbc【oracle】JDBCOracle
- JDBC codeJDBC
- jdbc作用JDBC