• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ResultSet.getString(0)

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If I code this in my program what could be the result and why?
Can I use it in the first place?
Seetesh
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
When used, gives Invalid Column index. Is 0 reserved for some variable?
Why only the ResultSet.getxxxx(1) has to start from column index from 1 onwards.
Seetesh
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Seetesh Hindlekar:
Hi,
When used, gives Invalid Column index. Is 0 reserved for some variable?
Why only the ResultSet.getxxxx(1) has to start from column index from 1 onwards.
Seetesh


I suppose this is a "because it does, so just accept it" answer. The JDBC API designers made a decision at some point that the column indexes would be base-1 instead of base-0 like you were expecting.
I wish all index-related methods were base-0 for consistency reasons. It is kind of annoying to have to remember which methods use 0 and which use 1. You just get used to it after a while. :roll:
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Blake,
----------- ur post ----------------
You just get used to it after a while.
------------ end of post ----------------
Can u come up with a good solution instead of the statement made?
Its mentioned in the JDK help that the column nos start from 1 onwards.
BTW, My question is still not answered.
Rgds,
Seetesh
 
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish,
well I think your question was answered by blake...more or less,(even the resultset itself does not have a row 0, you have to call on the resultset.next() to get to the first row.)
besides, the Drivers are not developed by sun, they are developed by the database vendors or atleast depend on the ODBC standard,...so it could just be a generally accepted standard....
I dont know but 0 might also have been reserved for some special reasons, some databases support indexing of the records, which can be queried also, but they do not form the structure of the table....then probably when you make some special Queries the 0 will have some indexed info??
Or it could just be that they stuck to Natural Numbers. some SQL expert could actually compare the Resultset and a Cursor in the RDBMS world, that could be a good insight too.
resukt of getString(0)\
java.sql.SQLException: Invalid column index
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.prepare_for_new_get(OracleStatement.java:3199)
at oracle.jdbc.driver.OracleStatement.getIntValue(OracleStatement.java:4264)
at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:510)
at test.datalayer.DbConnection.main(DbConnection.java:92)
[ April 01, 2004: Message edited by: RajaniKanth Bhargava ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic