prima ho aperto una discussione simile,
ma stavolta riguarda la cancellazione dal database ....
si puo' cancellare il contenuto di una riga prelevando i dati da delle textfield???
io ho provato a fare cosi':
[codice]
if(jButton2 == null) {
jButton2= new JButton();
jButton2.setText("Cancella dati");
jButton2.setCursor(Cursor.getPredefinedCursor(Curs or.HAND_CURSOR));
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
//System.out.println("ciao....");
cancellaarchivio(e);
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
});
}
return jButton2;
}
@SuppressWarnings("deprecation")
public void cancellaarchivio(ActionEvent e)throws SQLException, ClassNotFoundException{
SQLManager sqlm = new SQLManager("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
String query = "DELETE nome = '"+ TextNome.getText()+"', cognome= '"+ TextCognome.getText() +"', password ='"+ jPasswordField1.getText() +"', " +
" id_utente = '"+ TextID_Utente.getText() +"', telefono = '"+ TextTelefono.getText() +"',fax = '"+ TextFax.getText() +"', tipo_utente = '"+ TextTipo_Utente.getText() +"', email = '"+ TextEmail.getText() +"'," +
"dipartimento = '"+ TextDipartimento.getText() +"', img ='"+ TextImg.getText() +"' FROM Utente WHERE cognome = '" + this.getCognomeDocente() + "'";
System.out.println(query);
//System.out.println("**********: " + query);
//@SuppressWarnings("unused")
//ResultSet rs = sqlm.execute(query);
//while (rs.next()) {
//System.out.println("nome dalla query: " + rs.getString("nome"));
//}
//eseguire la query
//settare i parametri
//@SuppressWarnings("unused")
//boolean inserisci = sqlm.esegui(query);
//@SuppressWarnings("unused")
sqlm.esegui(query);
sqlm.close();
TextNome.setText("");
TextCognome.setText("");
jPasswordField1.setText("");
TextID_Utente.setText("");
TextTelefono.setText("");
TextFax.setText("");
TextTipo_Utente.setText("");
TextEmail.setText("");
TextDipartimento.setText("");
TextImg.setText("");
TextNome.requestFocus();
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
[/codice]
questa è l'eccezione:
[ECCEZIONE]
DELETE nome = 'Luciano', cognome= 'Fashon', password ='11111', id_utente = '10', telefono = '',fax = '', tipo_utente = '', email = '',dipartimento = '', img ='' FROM Utente WHERE cognome = 'Fashon'
java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Luciano', cognome= 'Fashon', password ='11111', id_utente = '10', telefono = '' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2001)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:11 68)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :1279)
at com.mysql.jdbc.Connection.execSQL(Connection.java: 2281)
at com.mysql.jdbc.PreparedStatement.execute(PreparedS tatement.java:1419)
at org.schedule.db.SQLManager.esegui(SQLManager.java: 89)
at org.schedule.oggetti.PannelloDocente.cancellaarchi vio(PannelloDocente.java:474)
at org.schedule.oggetti.PannelloDocente$3.actionPerfo rmed(PannelloDocente.java:435)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown 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.mouseRe leased(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(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn 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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
[/ECCEZIONE]