0

在更新任何字段的任何数据时,它会给出如下错误:

已创建驱动程序加载
语句

java.sql.SQLException:
在 sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
在 sun.jdbc.odbc.JdbcOdbc的 sun.jdbc.odbc.JdbcOdbc.createSQLException(
JdbcOdbc.java:6986 ) 的一般错误.SQLExecDirect(JdbcOdbc.java:3110)
在 sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338) 在 sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288) 在 sanskarwani.updateREGISTRATION1(sanskarwani.java:2792) 在 sanskarwani.access$700 (sanskarwani.java:29) 在 sanskarwani$8.actionPerformed(sanskarwani.java:1255) 在 javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) 在 javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) ) 在 javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) 在 javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) 在 javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) 在 java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) 在 java.awt.Component.processMouseEvent(Component.java:6038) 在 javax.swing.JComponent.processMouseEvent(JComponent.java:3260) 在 java. awt.Component.processEvent(Component.java:5803) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4410) at java.awt.Container.dispatchEventImpl (Container.java:2116) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在 java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) 在 java.awt.LightweightDispatcher.processMouseEvent(Container.java: 3986)在 java.awt.LightweightDispatcher.dispatchEvent(容器。java:3916) 在 java.awt.Container.dispatchEventImpl(Container.java:2102) 在 java.awt.Window.dispatchEventImpl(Window.java:2429) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:599) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在 java.awt.EventDispatchThread .pumpEventsForHierarchy(EventDispatchThread.java:173) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.爪哇:121)3916) 在 java.awt.Container.dispatchEventImpl(Container.java:2102) 在 java.awt.Window.dispatchEventImpl(Window.java:2429) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在 java. awt.EventQueue.dispatchEvent(EventQueue.java:599) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:173) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java: 121)3916) 在 java.awt.Container.dispatchEventImpl(Container.java:2102) 在 java.awt.Window.dispatchEventImpl(Window.java:2429) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在 java. awt.EventQueue.dispatchEvent(EventQueue.java:599) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:173) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java: 121)Container.dispatchEventImpl(Container.java:2102) 在 java.awt.Window.dispatchEventImpl(Window.java:2429) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在 java.awt.EventQueue.dispatchEvent(EventQueue .java:599) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Container.dispatchEventImpl(Container.java:2102) 在 java.awt.Window.dispatchEventImpl(Window.java:2429) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在 java.awt.EventQueue.dispatchEvent(EventQueue .java:599) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)2102) 在 java.awt.Window.dispatchEventImpl(Window.java:2429) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在 java.awt.EventQueue.dispatchEvent(EventQueue.java:599) 在 java. awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) 在 java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)2102) 在 java.awt.Window.dispatchEventImpl(Window.java:2429) 在 java.awt.Component.dispatchEvent(Component.java:4240) 在 java.awt.EventQueue.dispatchEvent(EventQueue.java:599) 在 java. awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) 在 java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Component.dispatchEvent(Component.java:4240) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread .java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Component.dispatchEvent(Component.java:4240) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread .java:183) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java :168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java :168) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)泵事件(EventDispatchThread.java:160)在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)泵事件(EventDispatchThread.java:160)在 java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

我的代码是:

String nmreg = cbnm.getSelectedItem().toString();

if(nmreg.equals(""))   //{
    JOptionPane.showMessageDialog(null," ENTER THE NAME ");

try
{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("\n Driver loaded");

    Connection con = DriverManager.getConnection("jdbc:odbc:wanisamajDB");
    Statement stmt = con.createStatement();

    System.out.println("statement is created");

    String qry = " UPDATE Registration1 set RegistrationNo = '"+cbregn.getSelectedItem()+"',SeniorPerson = '"+cbnm.getSelectedItem()+"', NativePlace = '"+tfplace.getText()+"',Kul = '"+tfkul.getText()+"', Gotra = '"+tfgotra.getText()+"' ,KulSwami = '"+tfswami.getText()+"', ResidensialAddress = '"+taraddr.getText()+"' , PinCode = '"+tfpcd.getText()+"', STDcode = '"+tfstdcode.getText()+"',TelephoneNo = '"+tftele.getText()+"', MobileNo = '"+tfmno.getText()+"', Email = '"+tfemail.getText()+"',Website ='"+tfweb.getText()+"',Education ='"+tfedu.getText()+"',Branch ='"+tfbrch.getText()+"',BloodGroup ='"+cbbldgrp.getSelectedItem()+"' where SeniorPerson='" +cbnm.getSelectedItem().toString()+"'" ;
             // String qry= " UPDATE Registration1 set SeniorPerson = '"+cbnm.getSelectedItem().toString()+"',NativePlace = '"+tfplace.getText()+"', Kul = '"+tfkul.getText()+"',Gotra = '"+tfgotra.getText()+"' , KulSwami = '"+tfswami.getText()+"', ResidensialAddress = '"+taraddr.getText()+"' , PinCode = '"+Integer.parseInt(tfpcd.getText())+"', STDcode = '"+Integer.parseInt(tfstdcode.getText())+"',TelephoneNo = '"+Integer.parseInt(tftele.getText())+"',MobileNo = '"+Integer.parseInt(tfmno.getText())+"',Email = '"+tfemail.getText()+"',Website ='"+tfweb.getText()+"',Education ='"+tfedu.getText()+"',Branch ='"+tfbrch.getText()+"',BloodGroup ='"+cbbldgrp.getSelectedItem().toString()+"' where RegistrationNo='" +Integer.parseInt(cbregn.getSelectedItem().toString())+"'" ;
              stmt.executeUpdate(qry);
              JOptionPane.showMessageDialog(null,"RECORD IS UPDATED SUCCESSFULLY ");
              System.out.println("QUERY");       

             // cbregn.setEditable(false);
              cbnm.setEditable(false);
              tfplace.setEditable(false);
              tfkul.setEditable(false);
              tfgotra.setEditable(false);
              tfswami.setEditable(false);
              taraddr.setEditable(false);
              tfpcd.setEditable(false);
              tfstdcode.setEditable(false);
              tftele.setEditable(false);
              tfmno.setEditable(false);
              tfemail.setEditable(false);
              tfweb.setEditable(false);
              tfedu.setEditable(false);
              tfbrch.setEditable(false);
              cbbldgrp.setEditable(false);
              con.close();
              stmt.close();
            }
//            catch(SQLException eM)
//            {
//            JOptionPane.showMessageDialog(null,"RECORD IS NOT FOUND ");
//            }
            catch(Exception et)
            {
                 et.printStackTrace();
              //  System.out.println("error:"+et.getMessage());
            }

请帮帮我

4

2 回答 2

1

为了避免sql-injection tru 使用方法PrepardStatment,它更容易使用并且最终得到相同的结果。

于 2011-04-08T07:39:09.957 回答
1

这是一个错字:“住宅”吗?

... ResidensialAddress = '"+taraddr.getText()+"' ...
于 2011-04-08T05:59:12.220 回答