private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
Connection conn=DbCon.conDB();
//String Mname =jComboBox1.getSelectedItem().toString();
String sql="delete Name from nowshowingmovie where Name = '"+jComboBox1.getSelectedItem().toString()+"'";
try{
pst=conn.prepareStatement(sql);
// pst.executeQuery();
pst.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"Movie Deleted Sucessfully");
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null, e);
}
}
2 issues:
In general the syntax for DELETE is
String sql = "delete from nowshowingmovie where Name = '"+jComboBox1.getSelectedItem().toString()+"'";
PreparedStatement
doesn't use the SQL String, i.e. just usepst.executeUpdate()
Side note: Since you're already using a PreparedStatement
you can use a placeholder to avoid SQL injection
attacks
String sql = "delete from nowshowingmovie where Name = ?";
pst.setString(1, jComboBox1.getSelectedItem().toString());
pst.executeUpdate();
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
Connection conn=DbCon.conDB();
//String Mname =jComboBox1.getSelectedItem().toString();
String sql="delete Name from nowshowingmovie where Name = '"+jComboBox1.getSelectedItem().toString()+"'";
try{
pst=conn.prepareStatement(sql);
// pst.executeQuery();
pst.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"Movie Deleted Sucessfully");
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null, e);
}
}
2 issues:
In general the syntax for DELETE is
String sql = "delete from nowshowingmovie where Name = '"+jComboBox1.getSelectedItem().toString()+"'";
PreparedStatement
doesn't use the SQL String, i.e. just usepst.executeUpdate()
Side note: Since you're already using a PreparedStatement
you can use a placeholder to avoid SQL injection
attacks
String sql = "delete from nowshowingmovie where Name = ?";
pst.setString(1, jComboBox1.getSelectedItem().toString());
pst.executeUpdate();
0 commentaires:
Enregistrer un commentaire