aspose file tools*
The moose likes JDBC and the fly likes jdbc DRIVER and MS Sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc DRIVER and MS Sql" Watch "jdbc DRIVER and MS Sql" New topic
Author

jdbc DRIVER and MS Sql

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Hi,
A year back I was working with MS sql server.
My query was something like "select name, age from emp"
My code

The above code was throwing an exception but when I read the string first and then the int the code was running fine.



I dont remember the driver which I had used. I want to know if this a driver bug or is this acceptable?


Groovy
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
It worked fine.... I've just tried with my Oracle Database...
Have u ever tried with the names of the columns? The same way as you did.... Try with the second column come first... In my program, it works fine also with the names of the columns


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Originally posted by Ko Ko Naing:
It worked fine.... I've just tried with my Oracle Database...
Have u ever tried with the names of the columns? The same way as you did.... Try with the second column come first... In my program, it works fine also with the names of the columns


AS I mentioned I faced the problem with MS SQL database only and unfortunately I dont remember the driver used. I know this works fine for oracle datbase. I am of the understanding that order should not matter when we use indexes for getting values from resultset.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Some JDBC drivers are known to be quite picky about the order in which you read the fields. The JDBC Tutoral and API book recommends, if I remember correctly, that for best compatibility you should read all the fields from a ResultSet, in the order in which they occur in the query.
- Peter
[ October 10, 2003: Message edited by: Peter den Haan ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Thanks Peter! Is this a problem with the database or the driver?
The JDBC Tutoral and API book recommends, if I remember corectly, that for best compatibility you should read all the fields from a ResultSet, in the order in which they occur in the query.

I strongly feel that this should be mentioned in the API docs or the JDBC spec. I havent come across this when read the api or spec. Did I miss something?
I feel that debugging this will be not so easy, I took some time before I figured it out and the exception messages were not hepful.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Pradeep Bhat:


AS I mentioned I faced the problem with MS SQL database only and unfortunately I dont remember the driver used. I know this works fine for oracle datbase. I am of the understanding that order should not matter when we use indexes for getting values from resultset.

Have u tried using columns' names? I wanna know the results too... Thanx...
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Originally posted by Ko Ko Naing:

Have u tried using columns' names? I wanna know the results too... Thanx...


no
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Pradeep Bhat:
Thanks Peter! Is this a problem with the database or the driver?
Not sure. Probably the combination of the two -- this all has to do with internal implementation detail (the way the resulting data is being streamed?) and is not part of the JDBC API (AFAIK). If funny restrictions like this are mentioned anywhere, it would probably be in the JDBC driver documentation.
- Peter
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
This is a problem that is specific to MS SQL Server(And maybe Access, too...) but it doen't matter if you use column names or column indices -- if you retreive them not in the order specified in the query, you will get an odd exception. This isn't a Java problem per se; it is a problem with the database driver. (Even if you connect to SQL Server through the JDBC-ODBC Bridge, you get the same results; the problem is on the DB end, not the driver end...)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc DRIVER and MS Sql
 
Similar Threads
MS Temporary tables and metadata
no dafault driver specified
Update inside Select statement
Nullpointer exception?
JDBC: What is the concrete class that implements the jdbc interfaces