我使用resultset
和getmetadata
查询Teradata数据库。出于某种原因,我发现使用C#很难得到结果。
这是Java中的代码:
public class T20905JD
{
public static String sUser = "guest";
public static String sPassword = "please";
public static void main(String args[])
{
// Creation of URL to be passed to the JDBC driver
String url = "jdbc:teradata://whomooz/TMODE=ANSI,CHARSET=UTF8";
// Creating a connection object
Connection con = DriverManager.getConnection(url, sUser, sPassword);
System.out.println(" User " + sUser + " connected.");
System.out.println(" Connection to Teradata established. \n");
DatabaseMetaData dbmd = con.getMetaData();
System.out.println(" DatabaseMetaData object created. \n");
ResultSet rs = dbmd.getSchemas();
// Display the database names
System.out.println(" DISPLAYING ALL DATABASE NAMES:\n");
while(rs.next())
{
System.out.println(" " + rs.getString("TABLE_SCHEM"));
}
}
}
如何在Teradata中使用C#获得相同的结果?
答案 0 :(得分:1)
这与C#和Java无关,而与Teradata无关。获取所有数据库(schemata)的最简单方法是查询:
SELECT DatabaseName, OwnerName
FROM DBC.DATABASES
WHERE DBKind = 'D';
如果要查看数据库的层次结构,则必须在查询中包含OwnerName。