Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ResultSetMetaData.getTableName(int column) is not working properly?

843859Feb 1 2006 — edited Oct 11 2007
Hi all
ResultSetMetaData.getTableName(int column) is not working properly. Its returning empty string with Oracle 10g and sql server 2005 both.
I am connecting to database through DSN (for oracle 10 g for sql server 2005).I am using JDK 1.5.The code that I am using is as follows
-------------------------------------------
import java.sql.*;
class ora_test{

public static void main (String args []) throws SQLException
{
Connection connection = null;
try {
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driverName);
System.out.println("Driver Initialized......");

String url = "jdbc:odbc:ravi2;UID=scott;PWD=tiger";
String username = "scott";
String password = "tiger";
connection = DriverManager.getConnection(url);
PreparedStatement ps=connection.prepareStatement("select * FROM emp");
ResultSetMetaData rsmt=ps.getMetaData();
for(int iCount=1;iCount<=rsmt.getColumnCount();iCount++)
{
String tempRow[]=new String [3];
tempRow[0]=rsmt.getColumnName(iCount);
tempRow[1]=rsmt.getTableName(iCount);
tempRow[2]=rsmt.getColumnTypeName(iCount);
System.out.println(tempRow[0]+"- "+tempRow[1]+"- "+tempRow[2]);
}
connection.close();

} catch (Exception e) {
e.printStackTrace();
}

}
}
-------------------------------------------
I want to fetch the column name, type and table name without executing the query. Can any one tell ,is there any othere ways for this?

Thanks,
-Ravi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 8 2007
Added on Feb 1 2006
7 comments
817 views