i am having this error while deleting record from database java.sql.SQLException: [Mi

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dilshad
    New Member
    • Nov 2014
    • 1

    i am having this error while deleting record from database java.sql.SQLException: [Mi

    java.sql.SQLExc eption: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression

    having this error while trying to delete record from database as follows plz help me with this.


    Code:
    			try
    			{
    				
    				String dsno=t[0].getText();
    				
    				
    				String qry="DELETE FROM sdetails WHERE Student no="+dsno+;
    				
    				stat.executeUpdate(qry);
    				
    				
    				JOptionPane.showMessageDialog(this, "Record is deleted", "done", JOptionPane.INFORMATION_MESSAGE);
    				
    				stat.close();
    				conn.commit();
    				conn.close();
    			}
    			catch(SQLException e)
    			{
    				System.out.println(e);
    			}
    Last edited by Rabbit; Nov 12 '14, 07:10 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    You wrote the student number column as two words: "Student no". Please look up the correct column name. Does it really have a space between? It is common practice not to use spaces in database column names, but underscores instead. But if you do not have the right to rename the database column, then use doublequotation marks:
    Code:
    String qry="DELETE FROM sdetails WHERE \"Student no\"="+dsno+;
    Remark:Your code is prone to an SQL injection attack. Just imagine somebody passes dsno="0; drop table sdetails". So try to use "prepared statements" instead.

    Comment

    Working...