我做的ATM虚拟提款机,取款时有问题,数据库里的数据就是不变,其他的查询可以查询得到,就是更新不了。
帮忙看看这个方法哪里出错了:
try {
Connection con=null;
Conn cc=new Conn();
con=cc.getConn();
Statement cmd=con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=cmd.executeQuery("select * from xinxi where zhanghao="+Integer.parseInt(jt.getText())+" and mima='"+jpwf.getText()+"'");
// System.out.println("select * from xinxi where zhanghao="+Integer.parseInt(jt.getText())+" and mima='"+jpwf.getText()+"'");
if(rs.next()) {
//绑定一个用户
mima m = new mima();
m.setzhanghao(rs.getInt(1)); //int 的形式获取此 ResultSet 对象的当前行中指定列的值。
m.setmima(rs.getString(2));
m.setmoney(rs.getInt(3));
atm1 a1 = new atm1();
a1.setM(m); //把用户绑定
}
else
JOptionPane.showMessageDialog(null,"密码或账号错误!");
jpwf.setText(null);
} catch(Exception ex){
ex.printStackTrace();}
帮忙看看这个方法哪里出错了:
try {
Connection con=null;
Conn cc=new Conn();
con=cc.getConn();
Statement cmd=con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=cmd.executeQuery("select * from xinxi where zhanghao="+Integer.parseInt(jt.getText())+" and mima='"+jpwf.getText()+"'");
// System.out.println("select * from xinxi where zhanghao="+Integer.parseInt(jt.getText())+" and mima='"+jpwf.getText()+"'");
if(rs.next()) {
//绑定一个用户
mima m = new mima();
m.setzhanghao(rs.getInt(1)); //int 的形式获取此 ResultSet 对象的当前行中指定列的值。
m.setmima(rs.getString(2));
m.setmoney(rs.getInt(3));
atm1 a1 = new atm1();
a1.setM(m); //把用户绑定
}
else
JOptionPane.showMessageDialog(null,"密码或账号错误!");
jpwf.setText(null);
} catch(Exception ex){
ex.printStackTrace();}
public void updateStu(int money)
{
int zhanghao=m.getzhanghao();
int lest=m.getmoney()-money;
System.out.println("您的余额是"+lest);
Connection con=null;
Conn cc=new Conn();
try{
con=cc.getConn();
PreparedStatement ps=con.prepareStatement("update xinxi set money=" +lest+ " where zhanghao=?");
// PreparedStatement ps=con.prepareStatement("update xinxi set money=? where zhanghao=?");
ps.setInt(1,zhanghao);
// ps.setInt(2,lest);
System.out.println("----00-----");
// ps.executeUpdate();
int n = ps.executeUpdate();
if(n>0) {
JOptionPane.showMessageDialog(null,"取款成功!");
m.setmoney(lest); }else {
JOptionPane.showMessageDialog(null,"取款失败!");
}
con.commit();
ps.close();
}catch(Exception e){
System.out.println("错误!");
e.printStackTrace();
}
finally{cc.closeConn(con);}
System.out.println("------11----");
}
4399
是不是绑定用户的问题
//绑定用户
private mima m;
public mima getM() {
return m;
}
public void setM(mima m) {
this.m = m;
} 必须重写一个类吗?我改成用静态变量传的了也是不对啊!
public void updateStu(int ZH)
{
int amoney=m.getmoney();
int lest=m.getmoney()-amoney;
System.out.println("您的余额是"+lest);
Connection con=null;
Conn cc=new Conn();
try{
con=cc.getConn();
PreparedStatement ps=con.prepareStatement("update xinxi set amoney=" +lest+ " where zhanghao=?");
ps.setInt(1,ZH);
int n = ps.executeUpdate();
if(n>0) {
JOptionPane.showMessageDialog(null,"取款成功!");
m.setmoney(lest);
}
else {
JOptionPane.showMessageDialog(null,"取款失败!");
}
con.commit();
ps.close();
}catch(Exception e){
System.out.println("错误!");
e.printStackTrace();
}
finally{cc.closeConn(con);}
}