代码如下:
最开始我两个SQL语句共用的st,报这个错误,查了一下,CSDN上有人说不能共用,就改了,
结果还是报这个错误,请大家指点一下是什么原因。
Connection conn = null;
PreparedStatement st = null;
PreparedStatement st2=null;
ResultSet rs = null;
String cust_name=null;
int logintm=0;
StringBuffer sql = new StringBuffer();
try {
conn = DBHelp.getConn();
sql.append("select cust_name,logintm from custinfo where cust_code=? and cust_pw=?");
st = conn.prepareStatement(sql.toString());
st.setString(1, username);
st.setString(2, password);
rs=st.executeQuery();
while(rs.next()){
cust_name=rs.getString("cust_name");
logintm=rs.getInt("logintm");
logintm=logintm+1;
sql.setLength(0);
sql.append("update dzyc_custinfo set logintm=? where nation_code=?");
st2=conn.prepareStatement(sql.toString());
st2.setInt(1, logintm);
st2.setString(2, username);
st2.executeUpdate();
flag=1;
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DBHelp.closeObject(rs);
DBHelp.closeObject(st);
DBHelp.closeObject(st2);
DBHelp.closeObject(conn);
}
------解决方案--------------------
lz下次发帖前还是先百度下吧
http://www.iteye.com/topic/882651