This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes Servlets&JDBC-CallableStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Servlets&JDBC-CallableStatement" Watch "Servlets&JDBC-CallableStatement" New topic
Author

Servlets&JDBC-CallableStatement

Marina
Greenhorn

Joined: Sep 05, 2000
Posts: 2
I use CallableStatement to call stored procedure.
Stored Procedure has two output parameter. When I want to read these output parameters, I am getting or Exception
(Stack Trace:java.lang.NumberFormatException:
at InsertNewContactServlet.doPost
InsertNewContactServlet.java:154)
or empty paramateters, while stored procedure always returns something. When I am getting Exception it complains exactly on this code: int temp=call.getInt(16);
But database is always updated.
Can anybody help me with this?
This is the code:


[This message has been edited by Jim Yingst (edited September 05, 2000).]
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
What are the data types that the stored procedure returns? If it returns char or varchar, you can't get it with a getInt() even if it always returns a varchar that contains numbers only. Use the getString() and use a conversion method to make it into an int.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Marina
Greenhorn

Joined: Sep 05, 2000
Posts: 2
Originally posted by Carl Trusiak:
What are the data types that the stored procedure returns? If it returns char or varchar, you can't get it with a getInt() even if it always returns a varchar that contains numbers only. Use the getString() and use a conversion method to make it into an int.

One of output parameters is int in the database, so in servlet I register it with call.registerOutParameter(16,Types.INTEGER);
and I am reading it as call.getInt(16)
Another parameter is nvarchar in the database, so I register it in servlet as call.registerOutParameter(17,Types.VARCHAR) and I read it as call.getString(17). So, first output parameter in stored procedure is int and I am reading it as int.
Why it doesn't work? What's wrong here?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well I'm not sure what's going on here either, but why don't you try changing the getInt(16) to a getString(16) and see what happens? You probably also need to change the registerOutParameter() to match to make this work. If it works, try printing out whatever the string is to see if that gives any clue what's going on. Two possible causes I can think of are (1) the manage_contact procedure is somehow outputting a string, or (2) your driver is converting all output to strings. The latter sounds stupid I know, but I think I once observed that situation using the standard JDBC/ODBC bridge driver. (Which I guess is one reason why that driver isn't recommended.) Good luck.


"I'm not back." - Bill Harding, Twister
Mark MSmith
Greenhorn

Joined: Aug 17, 2001
Posts: 1
Hi. I have this same problem too and happened to try your string idea already. . . it crashed tomcat with an illegal operation error! I keep getting the same numberFormat exception. I'm running tomcat with apache (both latest versions) on win 98 SE. I'm using the standard sun.jdbc.obdc.JdbcOdbc drivers to interface with MS SQL Server 7. Any suggestions to get out parameters from a stored procedure would be appreciated
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets&JDBC-CallableStatement