• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problems with ResultSetMetaData getTableName()

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ideally you shouldn't be having problems.
Can you show us the code?
 
Tapan Parikh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Btw the prob is that the string returned is an empty string ""
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
 
Tapan Parikh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Any ideas about this? Does anyone know if Sun's JDBCODBC driver implementation just doesnt support ResultSetMetaData's getTableName() fxn?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am just wondering whether metadata support is there for the File database-> Access?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I too have the same Problem.I am using oracle.jdbc.driver.OracleDriver Connection.
 
author & internet detective
Posts: 42102
933
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You showed up just in time for the waffles! And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic