Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2004

Tip: Looking for answers? Try searching our database.

For jdbc juru

Thread view: 
cc - 19 Nov 2004 11:54 GMT
Hi,
I have found one anomaly inside jdbc.

I have one table with one "small int" or "short" type column  (database
dependent).
The ResultSetMetaData.getColumnClassName(i) method  return "java.lang.Short"
class.
But Resultset.getObject(i) method return java.lang.Integer.

This is corrected?
Why Resultset.getObject(i) method  not return java.lang.Short class?

Thanks for your help.

Carlo
David Harper - 19 Nov 2004 13:38 GMT
Carlo wrote:
> I have found one anomaly inside jdbc.
>
[quoted text clipped - 6 lines]
> This is corrected?
> Why Resultset.getObject(i) method  not return java.lang.Short class?

The "anomaly" exists not in JDBC but in the database driver that you are
using.

Which kind of database are you working with?

Is it Oracle? DB2? Sybase? MySQL? ...?

What strings do DatabaseMetaData.getDriverName() and
DatabaseMetaData.getDriverVersion() return?

Inquiring minds are keen to know.

David Harper
Cambridge, England
cc - 19 Nov 2004 13:58 GMT
> Which kind of database are you working with?
> Is it Oracle? DB2? Sybase? MySQL? ...?

I try ODBC connection with DBMaker 4.0 and Microsoft Access
:-(

> What strings do DatabaseMetaData.getDriverName() and
> DatabaseMetaData.getDriverVersion() return?

With ODBC DBMaker 4.0:
Driver name:    JDBC-ODBC Bridge (DMAPI40.dll)
Driver version: 2.0001 (04.00.0000)

With ODBC Micorsoft Access:
Driver name:    JDBC-ODBC Bridge (odbcjt32.dll)
Driver version: 2.0001 (04.00.6304)

???
Carlo
Joe Weinstein - 19 Nov 2004 16:12 GMT
> Hi,
> I have found one anomaly inside jdbc.
[quoted text clipped - 11 lines]
>
> Carlo

Hi Carlo. As others have said, it's an anomaly of the given JDBC driver.
In this area you will find many drivers that 'blaze their own path'....
Oracle, for instance, will typically return a BigDecimal from getObject()
for just about every numeric column type. One way to get a Short via getObject()
regardless of the driver is to do this:

Short myShort = (Number)(myResultSet.getObject("myCol")).shortValue();

Number is the supertype of all Java numeric objects, and has a number of
useful methods.

Hope that helps,
Joe Weinstein at BEA
David Harper - 19 Nov 2004 16:30 GMT
> Oracle, for instance, will typically return a BigDecimal from getObject()
> for just about every numeric column type. One way to get a Short via getObject()
> regardless of the driver is to do this:
>
> Short myShort = (Number)(myResultSet.getObject("myCol")).shortValue();

Why not get the short value directly,

  short myShort = myResultSet.getShort("myCol");

and if Carlo really needs an object, he can make one afterwards:

  Short myShortObject  = new Short(myShort);

David Harper
Cambridge, England
Joe Weinstein - 19 Nov 2004 16:46 GMT
>> Oracle, for instance, will typically return a BigDecimal from getObject()
>> for just about every numeric column type. One way to get a Short via
[quoted text clipped - 13 lines]
> David Harper
> Cambridge, England

Absolutely right, David. And there is one more wrinkle: If the column
allows null values, then getShort() will return a 0 for a null value,
and the OP would have to call wasNull() after that to know whether it
was a real 0 or really a null. And my code would have failed too,
because the getObject() would have returned a null.
   Thus, if the user knows they want, they should ask for it, and then
check for null, if needed. If they call getObject(), it'll be obvious,
and if they know that they want/expect a short value, they can always
call wasNull() after it.
Joe
Joe
Lee Fesperman - 19 Nov 2004 21:57 GMT
> Hi,
> I have found one anomaly inside jdbc.
[quoted text clipped - 6 lines]
> This is corrected?
> Why Resultset.getObject(i) method  not return java.lang.Short class?

Please don't multi-post! Your question was properly answered on
comp.lang.java.programmer.

Despite what others have said, this is correct behavior according to the JDBC Spec. Get
yourself over to c.l.j.p to read the correct answer.

Signature

Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.firstsql.com)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.