/**
*
*/
package test_jdbc4;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import org.junit.Test;
import jdbc_util.JDBCUtils;
/**
* @Description 使用prepredStatement实现对数据的批量操作(删除、修改、查询原本就具有批量操作的特点),这里演示批量插入
* @author
* @version
* @date 2020年2月17日 下午2:14:51
*/
public class InsertTest {
/**
* 方式一:使用Statenment向goods表中添加1000条数据
*
* @throws Exception
*/
@Test
public void insertTest1() throws Exception {
Connection conn = JDBCUtils.getConnection();
Statement statement = conn.createStatement();
for (int i = 1; i <= 200; i++) {
String sql = "insert into goods(name) values('name_" + i + "')";
statement.execute(sql);
}
}
/**
* 方式二:使用preparedStatement向goods表插入1000条数据
*
* @throws Exce
关于向Mysql数据库中批量添加数据的逐步优化
最新推荐文章于 2023-11-30 17:06:48 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)