日期:2014-05-16 浏览次数:20376 次
public boolean insertJob(long jobid,List prlist,String time,int khid){
boolean b=false;
Connection conn=null;
PreparedStatement ps =null;?
conn = DB.getConnection();
String sql="insert into job(jobid,msisdn,sendtime,name,khid) values (?,?,?,?,?)";
try{
conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
for(int i=0;i<prlist.size();i++){
Partyregister pr=(Partyregister)prlist.get(i);
ps.setLong(1, jobid);
ps.setString(2,pr.getMsisdn());
ps.setTimestamp(3, Timestamp.valueOf(time));
ps.setString(4, pr.getName());
ps.setInt(5, khid);
ps.addBatch();
}
??? ps.executeBatch();
??? conn.commit();??
??? conn.setAutoCommit(true);
??? b=true;
}
catch(Exception e){
b=false;
??? System.err.println("ERROR:"+e);
??? }
?????? finally
?????? {
?????????? try
?????????? {
?????????????? ps.close();
?????????????? if(null!=conn)
?????????????? {
?????????????? conn.close();
?????????????? }
?????????? }
?????????? catch(SQLException sqle)
?????????? {
?????????? System.err.println("SQLException, sqle=" + sqle.toString());
?????????? }
?????? }
??????
return b;
}
?