的SQLException在任何它給錯誤像場的任何數據的更新:創建麻煩與更新語句
驅動程序加載
聲明值java.sql.SQLException:常規錯誤
在sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6986)
在sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
在sun.jdbc.odbc.JdbcOdbc.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 8.actionPerformed(sanskarwani.java:1255)(sanskarwani.java:29) 在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) 在javax.swing.AbstractButton中的$處理器(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) (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) 在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(Container.java:3916) 在java.awt.Container.dispatchEventImpl(Container.java:2102) 在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) 在java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) 在java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) 在java.awt中。 EventDispatchThread.pumpEvents(EventDispat chThread.java:168) 在java.awt.EventDispatchThread.pumpEvents(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());
}
幫我請
嘗試使用PreparedStatement進行更新查詢。 – 2011-04-08 05:29:50
不是這是問題,但你不想爲該更新語句使用where子句?你將會更新所有的行。 – MeBigFatGuy 2011-04-08 05:32:31
這是您第一次遇到上述更新錯誤嗎?嘗試只更新一個字段,然後檢查是否會出現相同的錯誤或嘗試執行硬編碼查詢。另外我更喜歡PreparedStatement,因爲Shashank_Itmaster提到了一個嘗試。 – ace 2011-04-08 05:55:05