日期:2014-05-16  浏览次数:20403 次

Test2.数据库批处理添加练习(mysql_java)
package JDBC.WildCat.com;

import java.sql.*;
public class TestBatch {

	/**
	 * 批处理添加练习
	 * @param args
	 */
	public static void main(String[] args)throws Exception {
		// step1. new一个Driver
		Class.forName("com.mysql.jdbc.Driver");
		//step2. 拿到一个连接
		String url = "jdbc:mysql://localhost/wild_java?user=root&password=family";
		Connection conn = DriverManager.getConnection(url);
		//step3.创建一个Statement
		Statement stmt=conn.createStatement();
			
		stmt.addBatch("INSERT INTO student5(id,NAME,email) VALUES(23,'周星驰','sdefa@qq.com');");
		stmt.addBatch("INSERT INTO student5(id,NAME,email) VALUES(24,'李连杰','sdef2@qq.com');");
		stmt.addBatch("INSERT INTO student5(id,NAME,email) VALUES(25,'成龙','sd4ea@qq.com');");
		stmt.executeBatch();
		stmt.close();
		conn.close();
	}

}