wood burning stoves 2.0*
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Getting Table Name" Watch "Getting Table Name" New topic
Author

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]
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbcdbc:Sample","","");
DatabaseMetaData meta = connection.getMetaData();
ResultSet rs = meta.getTables("",null,"",null);
System.out.println(rs.getObject(1));

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

[Method 2]
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbcdbc:Sample","","");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT Name,Address,Total FROM student" );
ResultSetMetaData metaData = resultSet.getMetaData();
System.out.println(metaData.getTableName(1));

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 ]

http://subodh-gupta.blogspot.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Table Name
 
Similar Threads
insert command is not working.
sql_handle_env failed
not insering all the records (please help!!)
Problem in fetching data from sql server 2005
STORING Resultset in String variable