2012-04-07 4 views
0

エラーは次のとおりです。com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:あなたのSQL構文で エラーが発生しています。 sun.reflect.NativeConstructorAccessorImplでsun.reflect.NativeConstructorAccessorImpl.newInstance0(ネイティブメソッド)で行1 に近い「book_id = 『DSP123』」 を使用する権利構文については、あなたの MySQLサーバのバージョンに対応するマニュアルを確認してください。 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) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) at com。 mysql.jdbc.MysqlIO .checkErrorPacket com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)でcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)で(MysqlIO.java:3609) com.mysqlで.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427) (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 Frame.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。 javax.swingでのjavax.swing.DefaultButtonModel.setPressedでjavax.swing.DefaultButtonModel.fireActionPerformedでAbstractButtonの$ Handler.actionPerformed(AbstractButton.java:2318) (DefaultButtonModel.java:387) (DefaultButtonModel.java:242) 。 plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)java.awt.Component.processMouseEvent(Component.java:6263)で javax.swing.JComponent.processMouseEvent(JComponent.java:3267)で のjavaで 。 awt.Component.processEvent(Component.java:6028)(Container.java:2099) atのコンテナで、コンテナをディスパッチしたときにコンテナが破損する可能性があります。 java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238) at java。 (Container.java:2048) at java.awt。 Component.dispatchEvent(Component.java:4460)at java.awt.EventQueu java.awt.EventDispatchThread.pumpOneEventForFiltersでe.dispatchEvent(EventQueue.java:599) (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(); 
    } 
} 

答えて

2

whereの前にスペースを挿入します。それがあるべきいったん

String sql1 = "update library.books set status = " + 1 
     + " where book_id = '" + bookid + "'"; 
+0

ああ私はそれを得た、それは愚かな間違いだった。 – Manish

0

チェック

String sql1 = "update library.books set status = 1 where book_id = '" + bookid + "'"; 
関連する問題