This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes setInt(String, int) I'm Lost! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "setInt(String, int) I Watch "setInt(String, int) I New topic
Author

setInt(String, int) I'm Lost!

Sean Cormican
Greenhorn

Joined: Aug 25, 2011
Posts: 8
Basically I'm running jdbc connection to an sql database and for some reason without any change in code i start to get the following errors:

Generated servlet error:
Type mismatch: cannot convert from int to Integer

Generated servlet error:
The method setInt(String, int) in the type CallableStatement is not applicable for the arguments (int, Integer)

While it would be nice if someone could just explain the reason for this, I would equally appreciate it if someone would be able to
explain how i might locate the source of these errors as the log only gives the opening <% line

thanks in advance

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Hi Sean. Welcome to The Ranch!

Well, the problem appears to be that you're using an integer as the first argument in a call to setInt. But, as the error tells you, and as you'll see if you look at the documentation for CallableStatement, the first argument should be a String. It's expecting the parameter name.

As for easier debugging - the main problem there is that you appear to be using Java code in a JSP file. That's an outdated practice. All your Java code should be in Java classes. That way, among other advantages, the compiler will give you much more useful information.
Sean Cormican
Greenhorn

Joined: Aug 25, 2011
Posts: 8
That seems understandable enough but i also use setString(Int indexReference, String x), surely this should also cause a problem should it not ?

also do you have any idea why it would complain about trying to convert from an int to an Integer

The most confusing part about all of this is that no code has been altered in any way and yet these errors just started to occur,

other errors in a separate jsp caused errors which I fixed by changing the String method contains(String x) to matches(String x) but when i
changed back to the contains(String x) method the error did not return ?

Any thoughts on this are greatly appreciated!
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Is there any chance that the version of Java you're running on has changed? There must be something strange going on if the code didn't change.
Sean Cormican
Greenhorn

Joined: Aug 25, 2011
Posts: 8
To the best of my knowledge there hasn't been an update, it was something that I was considering myself but, there are other programs running on the server which do not suffer the same errors, its hard not to believe that there is some external factor causing this
Subhas Bose
Greenhorn

Joined: Aug 21, 2011
Posts: 1

Hi Sean,
Did you change from PreparedStatement to CallableStatement. For this you can check the connection. prepareStatement or connection.prepareCall
because the setInt(int,int) is only defined in PreparedStatement. Since they are related, i dont think there should be a problem. But do check this once.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setInt(String, int) I'm Lost!
 
Similar Threads
int assignment
jsp interger values
int Session value problem
int Session value problem
overload method in boxing/unboxing