Anver Anver - 27 days ago 10
SQL Question

Java (netbeans): The database is connected to SQL Server, i need to update, and delete data from the netbeans interface

the data is being view for this code by the interface:

private void distable() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=77OOP062;user=sa;password=hnd";
Connection conn= DriverManager.getConnection(url);
String sql ="Select * from Customer";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}


and this is my update button code:
// i dont know how the code work over here
and this is my delete button code:

String query =
"DELETE FROM 'Customer' WHERE CustomerName="
+ jTextFieldCustomerName.getText();
executeSQLQuery(query,"Delete"); //error on this executeSQLQuery code

Answer Source

try this one instead of using executeSqlQuery, use this:

Statement statement = connection.createStatement();    
pst.executeUpdate(query);