aspose file tools*
The moose likes JDBC and the fly likes A query error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "A query error" Watch "A query error" New topic
Author

A query error

Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
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();


"A thinking mind never dies"
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
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

Joined: Dec 06, 2005
Posts: 1321

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

Joined: Dec 26, 2006
Posts: 49
thank you saif !
i heartly thanks to you for clearify.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A query error