File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQL Server and real data type 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 "SQL Server and real data type" Watch "SQL Server and real data type" New topic
Author

SQL Server and real data type

Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 125
    
    5

I'm using the SQL Server JDBC drivers provided by microsoft and right now I've un into a problem getting data from SQL Server where the column is the mssql type "real". I've tried getDouble() and getFloat() but the exception I get says

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Value can not be converted to requested type.

Anyone know of a FREE type 4 JDBC driver for SQL Server that knows how to handle reals?


Java EE Evangelist — Author, EJB 3 in Action 2nd Edition — Java Community Process Member
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Have you tried getBigDecimal()? Failing that, check out Sun's JDBC Driver database.

Jules
Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 125
    
    5

Yup, tried BigDecimal. My solution is to use getString() then use BigDecimal to convert it to a double. Not the prettiest but it works. I'm just surprised I need to do it.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
What type does rs.getMetaData().getColumnType(1) return (assuming your REAL column is column 1)? You'll need to look up the int it returns in java.sql.Types.

Jules
Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 125
    
    5

The type number returned is 7 and the type name is "real". As you all know there is no ResultSet.getReal() function and getDouble(), getFloat(), getBigDecimal() all do not work, the SQL exception is thrown.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Well, I'm afraid I draw a blank. This is Sun's helpful recommendation:

Here is the link to thefull page.

So you're obviously doing something wrong. You could always check the scale (getScale) and precision (getPrecision) using the ResultSetMetaData to see if the type is somehow too big. Or better still check the database! :roll:

Good luck!

Jules

[edited to add line breaks]
[ August 26, 2004: Message edited by: Jeanne Boyarsky ]
 
 
subject: SQL Server and real data type