0
votes

On update of any data of any of the field it giving error like:

Driver loaded
statement is created

java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6986)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338) at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288) at sanskarwani.updateREGISTRATION1(sanskarwani.java:2792) at sanskarwani.access$700(sanskarwani.java:29) at sanskarwani$8.actionPerformed(sanskarwani.java:1255) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) at java.awt.Component.processMouseEvent(Component.java:6038) at javax.swing.JComponent.processMouseEvent(JComponent.java:3260) at 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) at java.awt.Component.dispatchEvent(Component.java:4240) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2429) at java.awt.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) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

My code is:

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());
            }

help me please

2
Try using PreparedStatement to make update query.Shashank_Itmaster
not that this is the problem, but you don't want a where clause for that update statement? you will be updating all the rows.MeBigFatGuy
Is this the first time you've encountered the said error with update? Try to update only one field then check if the same error will appear or try execute a hard-coded query. Also I prefer PreparedStatement as Shashank_Itmaster mentioned give it a try.ace
Can you print out the query being run and update it here.Nishan

2 Answers

1
votes

Is this a typo: "Residensial"?

... ResidensialAddress = '"+taraddr.getText()+"' ...
1
votes

to avoid sql-injection tru using the method PrepardStatment, it is easier to use and get the same results at the end.