It's not a secret anymore!*
The moose likes JDBC and the fly likes how to get details without querying full table ResultSetMetaData 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 "how to get details without querying full table ResultSetMetaData " Watch "how to get details without querying full table ResultSetMetaData " New topic
Author

how to get details without querying full table ResultSetMetaData

sorabh jaiswal
Greenhorn

Joined: May 11, 2007
Posts: 10
Hi All,

I wish to get the metadata information from database.I want to write my code independent of the database. I am using the following code...

String queryString = "select employeeName,address from employee where 1 = -1"
ResultSetMetaData rsmd = null;
rs = stmt.executeQuery(queryString);
rsmd = rs.getMetaData();

rsmdSize = rsmd.getColumnCount();

for(int i = 1;i <= rsmdSize;i++){
System.out.println("the col types " + rsmd.getColumnTypeName(i) );
System.out.println("the Size types " + rsmd.getColumnDisplaySize(i));
}


There is a drawback in this, that select statement will search the full table for fetching the data bcoz the where clause is "where 1 = -1"
As if the employee table consist of billion records it will take lot of time.
Can anyone guide me how to get the details through resultset without searching the full table?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by sorabh jaiswal:
Hi All,

I wish to get the metadata information from database.I want to write my code independent of the database. I am using the following code...

String queryString = "select employeeName,address from employee where 1 = -1"
ResultSetMetaData rsmd = null;
rs = stmt.executeQuery(queryString);
rsmd = rs.getMetaData();

rsmdSize = rsmd.getColumnCount();

for(int i = 1;i <= rsmdSize;i++){
System.out.println("the col types " + rsmd.getColumnTypeName(i) );
System.out.println("the Size types " + rsmd.getColumnDisplaySize(i));
}


There is a drawback in this, that select statement will search the full table for fetching the data bcoz the where clause is "where 1 = -1"
As if the employee table consist of billion records it will take lot of time.
Can anyone guide me how to get the details through resultset without searching the full table?


So even if you get ResultSet of one row, you can get meta data information about table?

If yes, then will it work?

Select * from employee where rownum="1";

Or insert a dummy employee just for this purpose and do this:

Select * from employee where employeeName="dummyName";

BTW, any reason for providing a where clause (1=-1). Even if you don't provide, it will fetch all the rows.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get details without querying full table ResultSetMetaData
 
Similar Threads
Array index out of bounds exception
Guys and Girls use this cool program for output
ResultSetMetaData
How to get field size of a column in a data base table
How to view the Datatypes of the Columns of a Table in SQLSERVER