錯誤是:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您在您的SQL語法錯誤 ;檢查對應於您 MySQL服務器版本在1號線 使用近「book_id = 'DSP123」在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本機方法) 在sun.reflect.NativeConstructorAccessorImpl正確的語法手冊。的newInstance(NativeConstructorAccessorImpl.java:39) 在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 在java.lang.reflect.Constructor.newInstance(Constructor.java:513) 在com.mysql.jdbc。 Util.handleNewInstance(Util.java:411) 在com.mysql.jdbc.Util.getInstance(Util.java:386) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) 在COM。 mysql.jdbc.MysqlIO .checkErrorPacket(MysqlIO.java:3609) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) at com.mysql .jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) 在com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624) 在com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2345) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java :2330) at Frames.Books.jButton2ActionPerformed(Books.java:424) at Frames.Books.access $ 300(Books.java:26) at Frames.Books $ 4.actionPerformed(Books.java:181) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing。 AbstractButton的$ Handler.actionPerformed(AbstractButton.java:2318) 在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) 在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) 在javax.swing中。在java中的javax.swing.JComponent.processMouseEvent(JComponent.java:3267) 上的java.awt.Component.processMouseEvent(Component.java:6263) 。 awt.Component.processEvent(Component.java:6028)在java.awt.Container.dispatchEventImpl(Container.java:2099) at(java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Component.dispatchEvent(Component.java:4460) 在java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574) 在java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238) 在java的。 awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt。 Component.dispatchEvent(Component.java:4460) at java.awt.EventQueu e.dispatchEvent(EventQueue.java:599) 在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) 在java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) 在java.awt.EventDispatchThread。 pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java。awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
代碼是:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String bookid = jTextField2.getText();
String doi = "";
Calendar cal = new GregorianCalendar();
doi = doi + cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DAY_OF_MONTH);
String sql = "insert into library.issue values ('"+ bookid + "','librarian','"+ username + "','" + doi + "')";
try
{
int i = st.executeUpdate(sql);
if(i>0)
JOptionPane.showMessageDialog(null,"BOOK IS ISSUED","SUCCESS",JOptionPane.PLAIN_MESSAGE);
else
JOptionPane.showMessageDialog(null,"problem in issuing book","FAILURE",JOptionPane.ERROR_MESSAGE);
bookid = bookid.toUpperCase();
String sql1 = "update library.books set status = " + 1 + "where book_id = '" + bookid + "'";
PreparedStatement pstmt=c.prepareStatement(sql1);
int j= pstmt.executeUpdate() ;
//int j = st.executeUpdate(sql1);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
哦,我明白了,這是一個愚蠢的錯誤。 – Manish 2012-04-07 21:46:16