mysql批量插入

留着测试数据用

PreparedStatement pstmt = null;
		Connection con = null;
		try {
			con = JdbcUtil.getConnection();
			con.setAutoCommit(false);
			pstmt = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
					ResultSet.CONCUR_READ_ONLY);

			String[] lines = temp.split(ConstUtil.DELIM_ENTER, -1);
			for (int i = 0; i < lines.length; i++) {
				String[] pdArr = lines[i].split(ConstUtil.DELIM_ONE, -1);

				if (pdArr.length < 5)
					return;

				pstmt.setString(1, pdArr[0]);
				if (pdArr[1].length() > 13)
					continue;
				pstmt.setString(2, pdArr[1]);// isbn
				pstmt.setString(3, pdArr[2]);
				pstmt.setString(4, pdArr[3]);
				pstmt.setString(5, pdArr[4]);
				pstmt.addBatch();
			}

			pstmt.executeBatch();
			con.commit();

你可能感兴趣的:(mysql批量插入)