对于插入数据,代码如下,如果我每次都要插入很多语句,那我岂不是要调用下面这个函数很多次,我可以在红色的字那里套一个循环,因为我就是在不断的更新name,email之类的数据。
public boolean preUpdataCustomersTB(int id,String company,String name,String address,String email,String phone,String other)
...{
try
...{
PreparedStatement pstmt = connection.prepareStatement(
"update TB_CUSTOMERS SET company = ?, name = ?, address = ?, email = ?, phone = ?, other = ? WHERE ID = ?;");
[color=#FF0000]pstmt.setString(1, company);
pstmt.setString(2, name);
pstmt.setString(3, address);
pstmt.setString(4, email);
pstmt.setString(5, phone);
pstmt.setString(6, other);
pstmt.setInt(7, id);
pstmt.execute();[/color]
connection.commit();
} catch (SQLException e)
...{
// TODO 自动生成 catch 块
e.printStackTrace();
return false;
}
return true;
}
public boolean preUpdataCustomersTB(int id,String company,String name,String address,String email,String phone,String other)
...{
try
...{
PreparedStatement pstmt = connection.prepareStatement(
"update TB_CUSTOMERS SET company = ?, name = ?, address = ?, email = ?, phone = ?, other = ? WHERE ID = ?;");
[color=#FF0000]pstmt.setString(1, company);
pstmt.setString(2, name);
pstmt.setString(3, address);
pstmt.setString(4, email);
pstmt.setString(5, phone);
pstmt.setString(6, other);
pstmt.setInt(7, id);
pstmt.execute();[/color]
connection.commit();
} catch (SQLException e)
...{
// TODO 自动生成 catch 块
e.printStackTrace();
return false;
}
return true;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货