日期:2014-05-20  浏览次数:20808 次

java Access数据库带参更新 纠结,,,求解
问题:
  源代码(运行的部分):

String addtion = textField.getText();
System.out.println(addtion);
int addtion1=Integer.parseInt(addtion);
System.out.println(addtion1);
String user2;
user2 = LoginManager.user1;//获取LoginManager输入的user1
// System.out.println(user2);
//textField.setText(user2);
String password2;
password2=LoginManager.password1;//获取LoginManager输入的password1
//System.out.println(password2);
//textField.setText(password2);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
conn = DriverManager.getConnection("jdbc:odbc:atm", "", "");//连接数据库atm
ps = conn.prepareStatement("update atm set sum=sum+"+addtion1 +"where user=? and password=?");
//ps = conn.prepareStatement("update atm set sum=sum+addtion1 where user=? and password=?");
ps.setString(1,user2);
ps.setString(2,password2);
ps.executeUpdate();
conn.close();
ps.close();



运行出现的错误:

[Microsoft][ODBC Microsoft Access 驱动程序] 语法错误 (操作符丢失) 在查询表达式 'sum+100where user=Pa_RaM000 and password=Pa_RaM001' 中。

改成下面的红色代码运行,出现错误:
 [Microsoft][ODBC Microsoft Access 驱动程序] 参数不足,期待是 3。


求解(详细的解答最好有例子),各位大侠帮帮忙!!!!
谢谢了!!!







------解决方案--------------------
update atm set sum=sum+"+addtion1 +"where user=? and password=?"
改为:
update atm set sum=sum+"+addtion1+" where user=? and password=?"
------解决方案--------------------
那就是StringBuffer拼接字符串呗
------解决方案--------------------