wood burning stoves 2.0*
The moose likes JDBC and the fly likes ResultSet.getString(0) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet.getString(0)" Watch "ResultSet.getString(0)" New topic
Author

ResultSet.getString(0)

Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
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

Joined: Feb 13, 2004
Posts: 244
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

Joined: Sep 13, 2002
Posts: 331
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:


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
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

Joined: Mar 18, 2004
Posts: 128

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet.getString(0)
 
Similar Threads
media player applet
WA #1.....word association
Posting to bump up my count...
Text box value is not being completely filled with request attribute
The x900 effect ?