Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC - HSQLDB problem...

 
Raul Martinez
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a simple Java application that queries an HSQLDB 'server mode' database.
I have a table called

GB_DATA
ENT_ID int
ENT_FROM varchar(..)
ENT_MSG varchar(..)
ENT_DATE varchar(..)
ENT_TIME varchar(..)


I use GB_DATA table to store guestbook entry. My java code contains,

String sqlQuery = " SELECT ENT_ID, ENT_FROM, ENT_MSG, ENT_DATE,ENT_TIME " +
" FROM gb_data order by ent_date desc, ent_time desc ";
try {
st = conn.createStatement();
rs = st.executeQuery(sqlQuery);
meta = rs.getMetaData();
int colCount = meta.getColumnCount();
String[] fieldNames = new String[colCount];
for (int x =0; x < colCount; x++) {
fieldNames[x] = meta.getColumnName(x);
}
} catch (SQLException se) {
throw new SQLException (se.getMessage() + " - getEntries");
}


--- when executing the code, database connection is successful.. but during the executeQuery(..)
statement, the it throws an SQLException with message :

Column not found: 0 getEntries


About the table (GB_DATA)
I used HSQL Database Manager to issue a create table command to be able to create
the GB_DATA table. Is this the problem??

I'm totally confused with the error since, the columns in my SELECT statement are all
valid and exists in GB_DATA

jm
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, tricky stuff.
For some reason JDBC related things start at an index of 1 instead of 0.
Try revising your for loop to start at 1.

[ March 02, 2004: Message edited by: James Swan ]
 
Raul Martinez
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
solved! thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic