• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets&JDBC-CallableStatement

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marina
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic