浠婂ぉ鍦ㄥ仛鏌愰」鐩殑POC嫻嬭瘯錛岀敳鏂規(guī)彁渚涗簡涓涓笁鍗佷竾璁板綍鐨凾XT鏁版嵁鏂囦歡錛岄渶瑕佹妸璇ユ枃浠剁殑璁板綍鎻掑叆鍒版暟鎹簱涓紝鐢變簬欏圭洰閮ㄧ殑鍚屼簨鍦ㄦ惌寤烘祴璇曠幆澧冧腑鐢ㄧ殑鏄疢ysql鏁版嵁搴擄紝鍦ㄦ妸鏁版嵁瀵煎叆鍒版暟鎹簱涓敤鐨勬槸JDBC鐨勬壒澶勭悊銆備唬鐮佸涓?

private void batchParseGroup()
{
Connection con= null;
PreparedStatement ps =null;

try
{
con= DbConnectionManager.getConnection();
con.setAutoCommit(false);
String sql = " insert into jivegroup(uri,groupname,pgroupid,description,creationdate,modificationdate,priority,selfpriority) values(?,?,?,?,?,?,?,?)";
ps= con.prepareStatement(sql);

for(int i=0;i<groupList.size();i++)
{
Group group = groupList.get(i);
ps.setString(1, group.getUri());
ps.setString(2, group.getName());
ps.setString(3, group.getPgroupId());
ps.setString(4, group.getName());
ps.setString(5, ""+System.currentTimeMillis());
ps.setString(6, ""+System.currentTimeMillis());
ps.setInt(7, group.getPriority());
ps.setInt(8, group.getPriority());
ps.addBatch();

if(i%100==0)
{
ps.executeBatch();
}
}
con.commit();
ps.executeBatch();

} catch (SQLException e)
{
e.printStackTrace();

}finally
{
DbConnectionManager.closeConnection(ps, con);
}
}
鍦ㄦ祴璇曟椂錛屽彂鐜頒笁鍗佷竾鐨勬暟鎹眳鐒墮渶瑕佸崄鍒嗛挓宸﹀彸鐨勬椂闂淬傞鍏堟兂鍒扮殑灝辨槸Mysql鐨勭浉鍏抽厤緗槸涓嶆槸鏈夐棶棰橈紝鍙嶅淇敼浜哅ysql鐨勭浉搴旈厤緗弬鏁幫紝鏀舵晥鐢氬井銆?br />
鍦∕ysql鐨勫畼緗戜笂鏌ュ埌濡備笅錛?br /> http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-configuration-properties.html
鍏充簬rewriteBatchedStatements鍙傛暟錛孧ysql瀹樻柟鐨勮鏄庯細(xì)
Should the driver use multiqueries (irregardless of the setting of "allowMultiQueries") as well as rewriting of prepared statements for INSERT into multi-value inserts when executeBatch() is called? Notice that this has the potential for SQL injection if using plain java.sql.Statements and your code doesn't sanitize input correctly. Notice that for prepared statements, server-side prepared statements can not currently take advantage of this rewrite option, and that if you don't specify stream lengths when using PreparedStatement.set*Stream(), the driver won't be able to determine the optimum number of parameters per batch and you might receive an error from the driver that the resultant packet is too large. Statement.getGeneratedKeys() for these rewritten statements only works when the entire batch includes INSERT statements.
瑙e喅鍔炴硶錛?br /> 涓嬭澆鏈鏂扮殑JDBC鐨勯┍鍔ㄧ▼搴忋?br /> MYSQL URL鐨勯厤緗弬鏁板涓嬶細(xì)
jdbc:mysql://54.200.190.80:3306/ccb_ucstar?rewriteBatchedStatements=true
緇忚繃嫻嬭瘯銆備笁鍗佸涓囩殑鏁版嵁銆?0縐掑唴鎼炲畾錛?/div>
]]>