ResultSetMetaData.getTableName(int column) is not working properly?
843859Feb 1 2006 — edited Oct 11 2007Hi 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