This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

jdbc DRIVER and MS Sql

 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pradeep bhatt
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ko Ko Naing:

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



no
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 1840
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...)
 
Always look on the bright side of life. At least this ad is really tiny:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!