实现 mysql快速批量插入

代码实现部分:

//批量插入数据
		String sql = "insert into person  values(?,?,?)";
//		String sql = "delete from person";
		//?rewriteBatchedStatements=ture;
		String url = "jdbc:mysql://localhost:3306/huanlesong?rewriteBatchedStatements=true";
		String classname = "com.mysql.jdbc.Driver";
		String user = "root";
		String password = "root";
		try {
			Class.forName(classname);
			//PreparedStatement ps = DBHelper.getConnection().prepareStatement(sql);
			PreparedStatement ps =  DriverManager.getConnection(url, user, password).prepareStatement(sql);
			for(int i=0;i<20000;i++){
				ps.setString(1, UUID.randomUUID().toString());
				ps.setString(2, UUID.randomUUID().toString());
				ps.setString(3, UUID.randomUUID().toString());
				ps.addBatch();
			}
			ps.executeBatch();
//			ps.executeUpdate();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

mysql快速批量插入url

String url = "jdbc:mysql://localhost:3306/huanlesong?rewriteBatchedStatements=true";

猜你喜欢

转载自blog.csdn.net/logic_c/article/details/79787889