• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A query error

 
Amar Deep Singh Chaudhary
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers
please help me imediately.when i try to execute the code given below it throws an exception
that java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Missing semicolon (;) at end of SQL statement
.can anyboy help me to find out the error in the query.while the connection is created successfully.

PreparedStatement st1;
java.util.Date logintime=new java.util.Date();
String date=logintime.toString();
id=request.getParameter("loginid");

st1=con.prepareStatement("insert into admintable(Last_login) values(?) where emp_id=?");
st1.setString(1,date);
st1.setString(2,id);
j=st1.executeUpdate();
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amar Deep Singh Chaudhary:
st1=con.prepareStatement("insert into admintable(Last_login) values(?) where emp_id=?");


It seems like you want to UPDATE you record in your SQL Statement. If it is then use UPDATE Query instead of INSERT.

You can't use WHERE clause with INSERT SQL statement in this way.
 
Amar Deep Singh Chaudhary
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi saif why we can't use the Insert into command in such a way with where clause please specify me. thank You.

Amardeep Singh Chaudhary
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Amardeep,

let me clear you, in your WHERE clause you are checking emp_id in the same row, in which you going to insert.

You cannot check emp_id unless you insert the value. How can you check the value when you haven�t inserted it?

You have to insert the value first then only you can able to update your record.
 
Amar Deep Singh Chaudhary
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you saif !
i heartly thanks to you for clearify.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic