データベースを更新しようとしていますが、コードに構文エラーが発生しています..助けてください..「st.execute(statement);」に変更しようとしています. および「st.executeUpdate(ステートメント);」しかし、エラーはまだあります。これが私のコードです...
public void editBook(String inputTitle, String[] newBookInfo)
{
boolean result = false;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:database");
st = con.createStatement();
rs = st.executeQuery("select * from library");
while(rs.next())
{
if(boyerMoore(rs.getString("Title").toLowerCase(), inputTitle.toLowerCase()))
{
isbn = rs.getString("ISBN");
statement = String.format("UPDATE library SET ISBN = '%s', Title = '%s', Author = '%s', Publisher = '%s', Published Year = '%s', Available Copies = '%s', Total Copies = '%s', WHERE ISBN = '%s'", newBookInfo[0], newBookInfo[1], newBookInfo[2], newBookInfo[3], newBookInfo[4], newBookInfo[5], newBookInfo[6], isbn);
st.executeQuery(statement);
rs.close();
st.close();
con.close();
JOptionPane.showMessageDialog(null, "Edit Succes", "Succes", JOptionPane.PLAIN_MESSAGE);
result = true;
}
}
if(!result)
JOptionPane.showMessageDialog(null, "\"" + inputTitle + "\" not Found in the Library", "Error", JOptionPane.ERROR_MESSAGE);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
これが完全なスタックトレースです..
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
at dataBase.editBook(dataBase.java:161)
at mainFrame.actionPerformed(mainFrame.java:177)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)