Microsoft KB Archive/195471

= BUG: JDBC Stored Proc with Output Date Param Causes Exception =

Article ID: 195471

Article Last Modified on 2/11/2005

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition

-



This article was previously published under Q195471



SYMPTOMS
Calling a stored procedure with output Date parameters from JDBC can cause a java.lang.NumberFormatException. The exception text is of the form:

*** Number Format Exception *** java.lang.NumberFormatException: 

at java/lang/Integer.parseInt (Integer.java) at java/lang/Integer.parseInt (Integer.java) at java/sql/Timestamp.valueOf (Timestamp.java) at com/ms/jdbc/odbc/JdbcOdbcCallableStatement.getTimestamp

(JdbcOdbcCallableStatement.java)

at com/ms/jdbc/odbc/JdbcOdbcCallableStatement.getObject

(JdbcOdbcCallableStatement.java)

at sdate.main (sdate.java:30)



CAUSE
This happens in the implementation of the JDBC/ODBC bridge. Note that calling GetTimestamp instead of getObject produces the same problem.



RESOLUTION
Avoid using Date as an output parameter in a stored procedure.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
Create a stored procedure with the following SQL: -- start of SQL create proc SimpleDate2

@i1 int output, @i2 int output, @i3 int output, @Date4 datetime output as

select @i1 = 666,

@i2 = 777, @i3 = 888, @Date4 = getdate return 999

--- End of SQL The following Java will reproduce the error.

Note You must change UID and PWD to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database. Timestamp tsDate = new Timestamp(System.currentTimeMillis);

int i=-1, iobj=-1,k; try  { Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection"JDBC:ODBC:DRIVER={SQL   Server};   SERVER=(local);DATABASE=pubs;UID= ;PWD= ;"; for(i = 1; i < 100; i++ ) { CallableStatement stmt = conn.prepareCall(" { ? = call SimpleDate2(?, ?, ?, ?) }"); stmt.registerOutParameter(1, Types.SMALLINT); for(k=2;k<5;k++){ stmt.setInt(k,k+999); stmt.registerOutParameter(k, Types.INTEGER); } stmt.setObject(5, tsDate, Types.TIMESTAMP); stmt.registerOutParameter(5, Types.TIMESTAMP);

int count = stmt.executeUpdate;

Object obj=stmt.getObject(5); System.out.println(obj);

stmt.close;

System.gc; } conn.close;

} catch(NumberFormatException nfe)    { System.out.println("*** Number Format Exception ***"); nfe.printStackTrace ; }

}

Keywords: kbbug kbdatabase kbpending KB195471

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.