Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Server and real data type

 
Michael Remijan
Author
Ranch Hand
Posts: 130
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried getBigDecimal()? Failing that, check out Sun's JDBC Driver database.

Jules
 
Michael Remijan
Author
Ranch Hand
Posts: 130
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic