This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Getting Table Name 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 "Getting Table Name" Watch "Getting Table Name" New topic

Getting Table Name

Giri Thava
Ranch Hand

Joined: Jun 22, 2006
Posts: 38
How can I get the table name(s) from the database (Microsoft Access).

Assume a situation in which I don't know the table name, but I know the
database name (Sample.mdb).

I tried the following two methods.

[Method 1]
Connection connection = DriverManager.getConnection("jdbcdbc:Sample","","");
DatabaseMetaData meta = connection.getMetaData();
ResultSet rs = meta.getTables("",null,"",null);

When I run the above code fragment it throws the following Exception.
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

[Method 2]
Connection connection = DriverManager.getConnection("jdbcdbc:Sample","","");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT Name,Address,Total FROM student" );
ResultSetMetaData metaData = resultSet.getMetaData();

Above code fragment returns the table name, but I should have included
the table name in the SQL query.

Advance thanks.
subodh gupta
Ranch Hand

Joined: Jul 23, 2007
Posts: 203

use the above code in place of first method.
[ July 26, 2007: Message edited by: subodh gupta ]
wood burning stoves
subject: Getting Table Name
Similar Threads
Problem in fetching data from sql server 2005
not insering all the records (please help!!)
insert command is not working.
STORING Resultset in String variable
sql_handle_env failed