java连接sql修改数据问题 public void button3_performed(ActionEvent e)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(Exception e1)
{
e1.printStackTrace();
}
try
{
int number=Integer.valueOf(jTextField3.getText());
String name2=jTextField2.getText();
Connection con=DriverManager.getConnection("jdbc:odbc:shopmanage");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select goodsPrice from goods where goodsName='"+name2+"'");
while(rs.next())
{
float price=rs.getFloat("goodsPrice");
ResultSet rs2=stmt.executeQuery("select goodsNumber from goods where goodsName='"+name2+"'");
while(rs2.next())
{
int number2=rs2.getInt("goodsNumber");
if(number2>number)
{
float sum=number*price;
JOptionPane.showMessageDialog(null,"您需要支付: "+sum+" 元" );
int rs3=stmt.executeUpdate("update goods set goodsNumber=goodsNumber-number where goodsName='"+name2+"'");
;
}else
{
JOptionPane.showMessageDialog(null, "您需要的数量已经超出本店的存货量");
}
}
}
}catch(Exception e2)
{
e2.printStackTrace();
}
我想点击按钮 弹出信息框显示总价,如果购买的数量小于数据库中的总量,允许购买。然后修改数据库中商品数量,减掉购买量。但是int rs3=stmt.executeUpdate("update goods set goodsNumber=goodsNumber-number where goodsName='"+name2+"'");这一句有错误,goodsNumber=goodsNumber-number那里有错。求教怎么写
JavaSQL数据库
分享到:
------解决方案-------------------- "update goods set goodsNumber=goodsNumber-"+Integer.toString(number)+" where goodsName='"+name2+"'" ------解决方案--------------------