Ciao a tutti, sto sviluppando un piccolo programma di gestione cliente, ma sto avendo problemi con l'istruzione INSERT, vi posto il codice e l'errore così vi sarà tutto più chiaro.
e questo è l'errore che genera:codice:public void inserisciCliente(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+this.ottieniPercorso()); String sql = new String ("INSERT INTO cliente (nome,cognome,codiceF,dataNascita,luogoNascita,recapito1,recapito2,recapito3,email,residenza,note) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)"); PreparedStatement cmd = con.prepareStatement(sql); //PASSAGGIO ATTRIBUTI AL DATABASE cmd.setString(1, this.nome); cmd.setString(2, this.cognome); cmd.setString(3, this.codiceF); cmd.setString(4, this.dataNascita); cmd.setString(5, this.luogoNascita); cmd.setString(6, this.recapito1); cmd.setString(7, this.recapito2); cmd.setString(8, this.recapito3); cmd.setString(9, this.email); cmd.setString(10, this.residenza); cmd.setString(11, this.note); cmd.executeUpdate(); con.close(); JOptionPane.showMessageDialog(null, "Inserimento riuscito con successo!"); }catch(SQLException | ClassNotFoundException e){ JOptionPane.showMessageDialog(null, "Inserimento non riuscito!"); e.printStackTrace(); } }
premetto che ho controllato il database svariate volte e il nome della tabella (cliente) e il nome e il numero di campi corrispondono perfettamente.codice:java.sql.SQLException: [Microsoft][Driver ODBC Microsoft Access] Errore di sintassi nell'istruzione INSERT INTO. at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source) at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source) at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source) at Cliente.inserisciCliente(Cliente.java:51) at Gui$2.actionPerformed(Gui.java:265) 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)
Quindi non ho idea di che cavolo potrebbe essere.
Vi ringrazio anticipatamente,
siete i migliori!

Rispondi quotando