Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Problems with ResultSetMetaData getTableName() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problems with ResultSetMetaData getTableName()" Watch "Problems with ResultSetMetaData getTableName()" New topic
Author

Problems with ResultSetMetaData getTableName()

Tapan Parikh
Greenhorn

Joined: Jun 28, 2001
Posts: 26

I am having problems using the function getTableName() in class ResultSetMetaData.
I am using the SUN JDBCODBC Bridge to connect to MS Access... Any ideas? Is this not supported w/ this Driver?
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
ideally you shouldn't be having problems.
Can you show us the code?


Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Tapan Parikh
Greenhorn

Joined: Jun 28, 2001
Posts: 26

This is the very simple code I am using to test this fxnality (after it wasnt working in my other code). This result Set had 5 columns so there is definitely some columns here...
ResultSetMetaData rsmd = rs.getMetaData();
String currentTableName = rsmd.getTableName(1);
Tapan Parikh
Greenhorn

Joined: Jun 28, 2001
Posts: 26

Btw the prob is that the string returned is an empty string ""
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
This is a snippet of code from one of my programs. It works for me.
Bosun
------------------------------------------------------------
DatabaseMetaData myMT = conn.getMetaData();
String[] myTables = {"TABLE"};
ResultSet tables = myMT.getTables(null,
null, "%", myTables);
String tableName = null;

while (tables.next())
{
tableName = tables.getString("TABLE_NAME");
System.out.println(tableName);
}
System.out.println("DBMS: " + myMT.getDatabaseProductName() + " " + myMT.getDatabaseProductVersion());

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Tapan Parikh
Greenhorn

Joined: Jun 28, 2001
Posts: 26

This is not exactly my problem... I am trying to get the table associated with a specific column in a ResultSet generated by a SELECT query. This is important in the case of joins, and also when I just want to find out the particular Table associated with the Results in a ResultSet...
Tapan Parikh
Greenhorn

Joined: Jun 28, 2001
Posts: 26

Any ideas about this? Does anyone know if Sun's JDBCODBC driver implementation just doesnt support ResultSetMetaData's getTableName() fxn?
satish bora
Greenhorn

Joined: Jul 16, 2001
Posts: 18
I am just wondering whether metadata support is there for the File database-> Access?

Sa
Jayendranath Krishnamoorthy
Greenhorn

Joined: Oct 30, 2004
Posts: 1
Hi I too have the same Problem.I am using oracle.jdbc.driver.OracleDriver Connection.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Jayendranath,
Welcome to JavaRanch! Note that the original post is three years old. Things may have changed since then.

Can you explain the problem you are getting? Is there an exception being thrown?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jim Tough
Greenhorn

Joined: Nov 21, 2009
Posts: 3
Tapan Parikh wrote:
Any ideas about this? Does anyone know if Sun's JDBCODBC driver implementation just doesnt support ResultSetMetaData's getTableName() fxn?


I'm having this problem also. I know this discussion thread is old, but this one comes up in my Google search near the top, so here I am. I found this related post on another site:

http://fixunix.com/weblogic/223501-resultsetmetadata-gettablename-int-column-dont-work.html
Hi. Sorry to be the bearer of bad news, but Oracle's DBMS doesn't
send the information about what table a column came from, so the
oracle driver will never be able to implement that resultset
metadata call. Most DBMSes don't either, and so you will see that
99% of all JDBC drivers will also not implement that call to return
anything useful. Only Sybase, with their very latest driver and
a specific optional DBMS configuration, have done it. It takes
a change in the DBMS that most DBMS vendors will never bother to do.


This seems to be what I'm encountering. In a ResultSet from a SELECT statement with joins, there does not appear to be a way to determine what table a particular column in the result set came from. Not great if you have joined two tables that each have a column with the same name.


Jim Tough - SCJP, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with ResultSetMetaData getTableName()
 
Similar Threads
get the table names from my database
getTableName() on ResultSetMetadata
Java & MS Access
How to fetch Table Name
Bug in Oracle Driver? - getTableName