File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet.getString(0)

 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Blake Minghelli
Ranch Hand
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Raj Chila
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic