问题描述
packageLogin;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;publicclassAddNewGoodsextendsJFrameimplementsActionListener{JButtonbtOK,btCancel;JTextFieldtextGlassID,textGlassNum,textBrand,textSize,textColor,textProperty,textPlaceOrigin;Connectioncon;Statementsql;ResultSetrs;publicAddNewGoods(){Containercon=this.getContentPane();btOK=newJButton("确定");btCancel=newJButton("返回");btOK.addActionListener(this);btCancel.addActionListener(this);textGlassID=newJTextField(10);//IDtextGlassNum=newJTextField(10);textBrand=newJTextField(10);//品牌textSize=newJTextField(10);//尺寸textColor=newJTextField(10);//颜色textProperty=newJTextField(10);//属性textPlaceOrigin=newJTextField(10);//产地JPanelpan1=newJPanel();JPanelpan2=newJPanel();JPanelpan3=newJPanel();JPanelpan4=newJPanel();JPanelpan5=newJPanel();JPanelpan6=newJPanel();JPanelpan7=newJPanel();JPanelpan8=newJPanel();pan1.add(newJLabel("商品号"));pan1.add(textGlassID);pan2.add(newJLabel("数量"));pan2.add(textGlassNum);pan3.add(newJLabel("品牌"));pan3.add(textBrand);pan4.add(newJLabel("尺寸"));pan4.add(textSize);pan5.add(newJLabel("颜色"));pan5.add(textColor);pan6.add(newJLabel("属性"));pan6.add(textProperty);pan7.add(newJLabel("产地"));pan7.add(textPlaceOrigin);pan8.add(btOK);pan8.add(btCancel);Boxbox=Box.createVerticalBox();box.add(pan1);box.add(pan2);box.add(pan4);box.add(pan5);box.add(pan6);box.add(pan7);box.add(pan8);con.add(box);this.setTitle("增加新商品");this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setBounds(300,200,250,360);this.setVisible(true);this.setAlwaysOnTop(true);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==btOK){StringGlass_ID=textGlassID.getText();StringBrand=textBrand.getText();StringSize=textSize.getText();StringColor=textColor.getText();StringProperty=textProperty.getText();StringPlaceOrigin=textPlaceOrigin.getText();StringID=textGlassID.getText();if(ID.equals("")){JOptionPane.showMessageDialog(this,"商品号不能为空!","警告!!",JOptionPane.ERROR_MESSAGE);}else{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(Exceptione1){JOptionPane.showMessageDialog(this,"装载驱动失败","错误对话框",JOptionPane.ERROR_MESSAGE);}try{StringA="select*fromGoodsStroewhereGlass_ID='"+ID+"'";con=DriverManager.getConnection("jdbc:odbc:AAglass","","");sql=con.createStatement();rs=sql.executeQuery(A);if(rs.next());{StringqueryID=rs.getString("Glass_ID");if(queryID.equals(ID)){JOptionPane.showMessageDialog(this,"商品已经存在,请去商品库存管理直接添加!","警告!!",JOptionPane.ERROR_MESSAGE);//更新后消除更新的数据textGlassID.setText("");}//谢谢大家从这里开始就有问题了else{con=DriverManager.getConnection("jdbc:odbc:AAglass","","");sql=con.createStatement();StringinsertStatement="insertintoNewGoods"+"values('"+Glass_ID+"','"+Brand+"','"+Size+"','"+Color+"','"+Property+"','"+PlaceOrigin+"')";sql.executeUpdate(insertStatement);JOptionPane.showMessageDialog(this,"您你成功更新了数据","消息对话框",JOptionPane.INFORMATION_MESSAGE);//更新后消除更新的数据textGlassID.setText("");textBrand.setText("");textSize.setText("");textColor.setText("");textProperty.setText("");textPlaceOrigin.setText("");}}}catch(SQLExceptione2){JOptionPane.showMessageDialog(this,"您的输入有误!","错误对话框",JOptionPane.ERROR_MESSAGE);e2.printStackTrace();textGlassID.setText("");textGlassNum.setText("");}catch(Exceptione2){JOptionPane.showMessageDialog(this,"更新数据出错","错误对话框",JOptionPane.ERROR_MESSAGE);e2.printStackTrace();textGlassID.setText("");textGlassNum.setText("");}}}elseif(e.getSource()==btCancel){this.dispose();}}/***@paramargs*/publicstaticvoidmain(String[]args){newAddNewGoods();}}当queryID和ID不相等的情况下,也就是标注的后面else那执行时都会出现异常,执行SQLExceptione2,我看了下上面写的是无效的游标状态麻烦高手帮忙解决下看是数据库或者代码哪里出现问题了!
解决方案
解决方案二:
么看懂。。。。。
解决方案三:
看晕了。我顶上去
解决方案四:
没有人帮忙吗?我看了下书,我觉得可能是游标没释放的问题,请问有谁知道怎么在java中释放游标啊!