String insertSQL = "Insert into table1(col1) values(?)";
String deleteSQL = "Delete from table1 where col1 = ?";
con.setAutoCommit(false);
PreparedStatement pts = con.prepareStatement(insertSQL);
PreparedStatement pts2 = con.prepareStatement(deleteSQL);for (int index = 0; index < list.size(); index++)
{
pts2.setInt(1,index);<<pts 应该是先出入才能有删除吧?!
pts2.executeUpdate();<<ptspts.setInt(2,index);<<pts2
pts.executeUpdate();<<pts2
}
String deleteSQL = "Delete from table1 where col1 = ?";
con.setAutoCommit(false);
PreparedStatement pts = con.prepareStatement(insertSQL);
PreparedStatement pts2 = con.prepareStatement(deleteSQL);for (int index = 0; index < list.size(); index++)
{
pts2.setInt(1,index);<<pts 应该是先出入才能有删除吧?!
pts2.executeUpdate();<<ptspts.setInt(2,index);<<pts2
pts.executeUpdate();<<pts2
}
那万一我查入不成功
那对于数据一致性怎么来保证?
因为我要从一个XML文件中读取数据
然后再导入数据库中
在查入前要删除相同的数据在MIS中这是一点没问题的啊
conn.setAutoCommit(false) ;
java.sql.PreparedStatement prstmt=null; //删除原有图片
String sqlimagedelete="delete from T_PICNEWSINFO where newssn='"+this.sn+"'";
prstmt=conn.prepareStatement(sqlimagedelete) ;
prstmt.executeUpdate() ;
//先添加图片信息
String sql="insert into T_PICNEWSINFO (NEWSSN,PICCON) values (?,?)";
FileInputStream str=new FileInputStream(image);
prstmt=conn.prepareStatement(sql) ;
prstmt.setString(1,this.sn );
prstmt.setBinaryStream(2,str,str.available() );
prstmt.executeUpdate() ; //然后更新图片标志
String sql_picflag="update t_newsinfo set picflag='p' where sn='"+this.sn +"'";
prstmt=conn.prepareStatement(sql_picflag) ;
prstmt.executeUpdate() ; conn.commit() ;
conn.setAutoCommit(true) ;
SQLException :java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC
]Can't start a cloned connection while in manual transaction mode.
用addBatch,executeBatch可以了