Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with integer values

 
gaurav chhabra
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir i m using MS ACCESS and JSP........i want to interconnect the both....but i m facing problem while inserting the values of the integer........the code is that.............

String lastused = request.getParameter("last_used"+i);
int last_used = Integer.parseInt(lastused);

String query = "insert into skills values(1 , '" + skill_type + "' , '" + skill_name + "', '" + version + "', '" + last_used + "' , '" + proficiency_level + "', '" + exp_in_years + "' ,'" + exp_in_months + "')";

please tell me the error

thank you
gaurav
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't told us what error you are getting. If you tell us what the problem is, then perhaps we can help.

In general, if you use PreparedStatement, then set the parameters using the appropriate methods (setInt(int, int), setString(int, String)), then you will have neater code, and be less likely to encounter these kinds of errors.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
I agree with Horatio that you should use PreparedStatement. (You should also try to keep JDBC out of your JSP, but that's another story.) Given that, it is still useful to understand the error because it applies to pure SQL queries too.


Last used is a numeric field. Therefore, it shouldn't have quotes around it. The quotes tell your database that last used is a string. Then it has errors comparing two different types.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic