Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes problem with integer values Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "problem with integer values " Watch "problem with integer values " New topic
Author

problem with integer values

gaurav chhabra
Ranch Hand

Joined: Jul 24, 2004
Posts: 109
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

Joined: Feb 23, 2005
Posts: 221
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 26241
    
  66

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: problem with integer values
 
Similar Threads
insertion into the database
Binary in java - guide me
Reverse 5 digit number by multiplying 4
calculator - logic problem
Bitsets and memory consumption