tags:

views:

8

answers:

1
result=sqlstring.executeQuery("select distinct table_name,owner from all_tables ")

rs.append(str(i)+' , '+result.getString("table_name")+' , '+result.getString("owner"))

If i want to display the query select * from all_tables or ' select count(*) from all_tables'

how can i get the output to display . Please suggest thanks

A: 

As in another your question: to show query results where you do not know how many columns query returns you must use metadata (best) or iterate and finish when getString(i) raises exception.

If you know how many columns is returned, as in cnt(*) case you can simply use rs.getString(1):

rs = conn.executeQuery("select count(*) from my_table")
while (rs.next()):
   cnt = rs.getString(1)

With cnt(*) you can use getInt(1), or name column using AS:

select count(*) as rec_cnt from my_table

and get it using rec_cnt = rs.getInt('rec_cnt').

If you use JDBC you should read something about it and get familiar with Java doc like: RecordSet

Michał Niklas