public static void insert(ArrayList<MsgBean> am) throws SQLException
{
Connection conn=null;
try {
conn=DBopertate.connection();
PreparedStatement ppst=conn.prepareStatement("insert into testtable (search_name1,search_name2,search_name3,search_sort,del_flag) values (?,?,?,?,'1')");
for (int i=0;i<am.size();i++) //for循环里面压根不执行
{
MsgBean tmp=new MsgBean();
tmp=am.get(i);
ppst.setString(1, tmp.getSearch_name1());
ppst.setString(2, tmp.getSearch_name2());
ppst.setString(3, tmp.getSearch_name3());
ppst.setInt(4, tmp.getSearch_sort());
ppst.addBatch();
}
ppst.executeBatch();
//System.out.println("hello");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if (conn!=null)
{
try {
conn.close();
} catch (Exception e2) {
// TODO: handle exception
}
finally
{
conn=null;
}
}
}
}
{
Connection conn=null;
try {
conn=DBopertate.connection();
PreparedStatement ppst=conn.prepareStatement("insert into testtable (search_name1,search_name2,search_name3,search_sort,del_flag) values (?,?,?,?,'1')");
for (int i=0;i<am.size();i++) //for循环里面压根不执行
{
MsgBean tmp=new MsgBean();
tmp=am.get(i);
ppst.setString(1, tmp.getSearch_name1());
ppst.setString(2, tmp.getSearch_name2());
ppst.setString(3, tmp.getSearch_name3());
ppst.setInt(4, tmp.getSearch_sort());
ppst.addBatch();
}
ppst.executeBatch();
//System.out.println("hello");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if (conn!=null)
{
try {
conn.close();
} catch (Exception e2) {
// TODO: handle exception
}
finally
{
conn=null;
}
}
}
}