81,095
社区成员
发帖
与我相关
我的任务
分享
<%
String[] names={"A","B","C","D"};
/* 数据库连接的固定步骤 */
Class.forName("com.mysql.jdbc.Driver");//导入驱动
String url = "jdbc:mysql://localhost:3306/test";//建立连接字符串
String username = "test";//存储用户名
String password = "123456";//存储密码
Connection conn =DriverManager.getConnection(url, username, password);//获得数据库连接
try{
Statement stmt=conn.createStatement();
stmt.clearBatch();
for(int i=0;i<names.length;i++){
stmt.addBatch("insert into tb_batch(name) values('"+names[i]+"')");
}
out.println("批量添加成功");
stmt.executeBatch();
stmt.close();
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
%>