Questo è quello che ho provato a fare ... ora come ora al click del bottone non fa altro che azzerarmi le jtextfield generando un'eccezione... Perche'??
[ECCEZIONE]
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 '('Enrichetta', 'Gentile', '00001', '1', '080-5443271','080-5443271', 'Dottoressa' 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.modificaarchi vio(PannelloDocente.java:399)
at org.schedule.oggetti.PannelloDocente$2.actionPerfo rmed(PannelloDocente.java:365)
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]
il codice che ho utilizzato è questo:
codice:
private JButton getJButton1() {
if(jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("Modifica dati");
jButton1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
//System.out.println("ciao....");
modificaarchivio(e);
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
});
}
return jButton1;
}
@SuppressWarnings("deprecation")
public void modificaarchivio(ActionEvent e)throws SQLException, ClassNotFoundException{
SQLManager sqlm = new SQLManager("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
String query = "update Utente set ('"+ TextNome.getText() +"', '"+ TextCognome.getText() +"', '"+ jPasswordField1.getText() +"', " +
"'"+ TextID_Utente.getText() +"', '"+ TextTelefono.getText() +"','"+ TextFax.getText() +"', '"+ TextTipo_Utente.getText() +"', '"+ TextEmail.getText() +"'," +
"'"+ TextDipartimento.getText() +"', '"+ TextImg.getText() +"')where cognome = '" + this.getCognomeDocente() + ")";
//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")
boolean inserisci = 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
}