ORACLE 批量 INSERT

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011134399/article/details/78022253
 String str = req.getParameter("data"); 
 
JSONObject jo = JSONObject.fromObject(str);
Connection connection = DataProxool.getOneConnection();// 获取一个连接池
PreparedStatement cmd = null;
try {

connection.setAutoCommit(false);
cmd = connection.prepareStatement("INSERT INTO BN_OFFLINE_IMPORT(NETBAR_ID,IDENTITY_ID,IMPORT_MONEY) values(?,?,?)");  
long netbarId = jo.getLong("netbarId");
JSONArray json = JSONArray.fromObject(jo.get("data")); // 首先把字符串转成 JSONArray  对象

if(null!=json && 0 < json.size()){
 for(int i=0;i<json.size();i++){
   
   JSONObject job = json.getJSONObject(i);  
   cmd.setLong(1, netbarId);
   cmd.setString(2, job.getString("idCard"));
   cmd.setDouble(3, job.getDouble("money"));
           try {
cmd.executeUpdate();

} catch (SQLException e) {

}
}
}

connection.setAutoCommit(true);
       connection.commit();
       cmd.close();
       connection.close();

} catch (Exception e) {

e.printStackTrace();
}

猜你喜欢

转载自blog.csdn.net/u011134399/article/details/78022253