ResultSetMetaData.getTableName(int column) don't work? - Weblogic

This is a discussion on ResultSetMetaData.getTableName(int column) don't work? - Weblogic ; hello i write a sql clause-"select * from emp",and want to connect to oracle database(scott/tiger) in my java programmer,after it is executed,the resultset(rset) can be returned correctly,then i invoke following clause: rset.next(); System.out.println(rset.getString(2)); System.out.println(rset.getMetaData().getTableName (2)); the first clause can return ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: ResultSetMetaData.getTableName(int column) don't work?

  1. ResultSetMetaData.getTableName(int column) don't work?


    hello
    i write a sql clause-"select * from emp",and want to connect to oracle database(scott/tiger)
    in my java programmer,after it is executed,the resultset(rset) can be returned
    correctly,then i invoke following clause:

    rset.next();
    System.out.println(rset.getString(2));
    System.out.println(rset.getMetaData().getTableName (2));


    the first clause can return the correct result("smith"),but the second clause
    return the empty string(" "),the correct result should be "emp".even i change
    to use the OracleConnection,OracleStatement and OracleResultSet,it still don't
    work,why?who can help me,and how can i return the table name that the column belong
    to?


    thank you!


  2. Re: ResultSetMetaData.getTableName(int column) don't work?


    I would suggest you specify all of the columns you are expecting in your sql.
    For example: "select fname, lname from emp". Doing a select * will make your
    code dependent on how the table was built and it should be avoided. Perhaps you
    are just returning a column you don't expect at position 2.

    -Peter


    "zhebincong" wrote:
    >
    >hello
    >i write a sql clause-"select * from emp",and want to connect to oracle
    >database(scott/tiger)
    >in my java programmer,after it is executed,the resultset(rset) can be
    >returned
    >correctly,then i invoke following clause:
    >
    >rset.next();
    >System.out.println(rset.getString(2));
    >System.out.println(rset.getMetaData().getTableName (2));
    >
    >
    >the first clause can return the correct result("smith"),but the second
    >clause
    >return the empty string(" "),the correct result should be "emp".even
    >i change
    >to use the OracleConnection,OracleStatement and OracleResultSet,it still
    >don't
    >work,why?who can help me,and how can i return the table name that the
    >column belong
    >to?
    >
    >
    >thank you!
    >



  3. Re: ResultSetMetaData.getTableName(int column) don't work?



    zhebincong wrote:

    > hello
    > i write a sql clause-"select * from emp",and want to connect to oracle database(scott/tiger)
    > in my java programmer,after it is executed,the resultset(rset) can be returned
    > correctly,then i invoke following clause:
    >
    > rset.next();
    > System.out.println(rset.getString(2));
    > System.out.println(rset.getMetaData().getTableName (2));


    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.
    Joe

    >
    >
    > the first clause can return the correct result("smith"),but the second clause
    > return the empty string(" "),the correct result should be "emp".even i change
    > to use the OracleConnection,OracleStatement and OracleResultSet,it still don't
    > work,why?who can help me,and how can i return the table name that the column belong
    > to?
    >
    >
    > thank you!
    >



  4. Re: ResultSetMetaData.getTableName(int column) don't work?

    I am using jconnect 5.5 driver for sybase. we are executing stored
    procedures that may update or return a resultset along with output
    parameter and return value as well. I faced similar problem of this
    exception while trying to do
    stmt.getInt(1).
    I always got this problem whenever I am doing stmt.executeQuery().
    this for sure returns me a resultset but while reading return value,
    it just throws exception.
    By chance, I came upon a solution for this problem, though I have a
    lot to make sure it works in all the cases.
    simply write following lines before reading the return value.

    ResultSet rs = stmt.getResultSet();
    if(rs!=null)
    {
    rs.next();
    rs.previous();
    }
    // now u can read return value
    stmt.getInt(1);

    this has worked for me, may be it will help. but for sure it looks
    weird.

    thanks!
    Mayur

+ Reply to Thread