473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

java.sql.SQLException: [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.


Expand|Select|Wrap|Line Numbers
  1.             try
  2.             {
  3.  
  4.                 String dsno=t[0].getText();
  5.  
  6.  
  7.                 String qry="DELETE FROM sdetails WHERE Student no="+dsno+;
  8.  
  9.                 stat.executeUpdate(qry);
  10.  
  11.  
  12.                 JOptionPane.showMessageDialog(this, "Record is deleted", "done", JOptionPane.INFORMATION_MESSAGE);
  13.  
  14.                 stat.close();
  15.                 conn.commit();
  16.                 conn.close();
  17.             }
  18.             catch(SQLException e)
  19.             {
  20.                 System.out.println(e);
  21.             }
Nov 11 '14 #1
1 1372
chaarmann
785 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. 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.
Nov 12 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris Taylor | last post by:
I keep getting the following message when trying to delete a single record from the table. "Search key was not found in any record" The record I'm trying to delete has errors in it and when...
0
by: RAllsopp | last post by:
I am having trouble deleting a record from a subform. I actually have a main form with two subforms, one dependent on the record selected in the other. The user selects a record to view on the...
3
by: bill_hounslow | last post by:
I'm trying to transfer data from one Sql Server into a table on another, using a simple INSERT query in an Access database with links to tables on both servers (the reasons for this are complicated...
3
by: rivka.howley | last post by:
I recently added some code to the BeforeUpdate event of a text box on a form. The code uses the new value in the text box to recalculate some values in another table, which is shown in a subform on...
6
by: Jeff | last post by:
Has anyone had any luck accessing an Oracle database from a web service? I have a C# DLL with various code to query an Oracle database. If I call the methods in this DLL from a Windows Forms...
3
by: Chris Thunell | last post by:
I am trying to delete all the records in a table, but I keep getting a system.data.dbconcurrency exception. Is there an easy was to delete all the records in a sql table? Here is my code... i...
3
by: Thaqalainnaqvi | last post by:
There appears to be an error with the database. You can try to refresh the page by clicking here. Error Returned mySQL query error: SELECT t.forum_id, COUNT(p.author_id) as f_posts FROM...
2
by: david720 | last post by:
Error 3167 Record is deleted And Sometimes the main entry form displays a record in the form where all fields are "#Delete" Why do we get this error sometimes (about 2 times a week)? It...
0
by: Cherrish Vaidiyan | last post by:
sir, The following are the steps that i followed in setting up standby database on Red hat Linux 9. i am using Oracle 9i. i have followed the steps in this site : ...
6
by: Joe Y | last post by:
I have a MainForm containg a datasheet SubForm. I want Access to alert user when closing or leaving the record in the MainForm if there is any data change. To users, adding or deleting record in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.