/**
* JDBC批量操作
* @author ZHQL
*/
public class Test06 {
public static void main(String[] args) {
String url ="jdbc:mysql://localhost:3306/db1726";
Connection conn = null;
Statement psm = null;
try {
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
//创建数据库连接
conn = DriverManager.getConnection(url,"u1726","u1726");
//创建语句
String sql = "INSERT INTO t_class(NAME,CHARGER,CREATE_DATE)"
+ "VALUES ('测试班级','李小凤',NOW())";
psm = conn.createStatement();
for (int i = 0; i < 100; i++) {
psm.addBatch(sql);//加入批量
}
psm.executeBatch();//批量提交
} catch (Exception e) {
e.printStackTrace();
}finally{
//后打开要先关闭
try {
psm.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
/**
* JDBC执行增删改演示(DBUtil)
* @author ZHQL
*/
public class Test07 {
public static void main(String[] args) {
try {
String sql = "update t_class set name = '班级名称1' where id = 11";
int i = DBUitl.update(sql);
System.out.println("更新的行数:" + i);
} catch (Exception e) {
e.printStackTrace();
}
}
}
版权声明:本文为qq_39089814原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。