i'm trying to delete selected row from jtable and database together but i'm getting syntax error. Might be cause i'm using varchar or really the syntax is just wrong in this case?
btnNewButton_2 = new JButton("Dzēst");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Statement statement = null;
try {
int tableRow = table_1.getSelectedRow();
Object Kods = table_1.getValueAt(tableRow, 0);
Object Nosaukums = table_1.getValueAt(tableRow, 1);
Object Inventara = table_1.getValueAt(tableRow, 2);
Object Uzskaites = table_1.getValueAt(tableRow, 3);
Object Iegad = table_1.getValueAt(tableRow, 4);
Statement stmt = null;
Connection connection = ConnectDB();
String sql = "DELETE FROM users " +
"WHERE Kods = " + Kods + " AND Nosaukums = '" + Nosaukums + "' AND Inventara Nr = " +
Inventara + " AND Uzskaites vertiba = '" + Uzskaites + "' AND Iegades vertiba = " + Iegad;
stmt = connection.createStatement();
stmt.executeUpdate(sql);
} catch (SQLException ex) {
Logger.getLogger(dddddddd.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Nav ievadita visa informacija");
}
ERROR:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Nr = ttttt AND Uzskaites vertiba = '3.0' AND Iegades vertiba = 3.0' at line 1
Database variables:
Kods -Index -int(255)
Nosaukums - varchar(255)
Inventara Nr - varchar(255)
Uzskaites vertiba - float
Iegades vertiba - float
PreparedStatements