public static List getTableName()
{
List tableNameList=new ArrayList();
try
{
// String driverClassName=loadProtocal("driverClassName");//定义驱动
// String url=loadProtocal("url");;//定义连接字符串
// String userName=loadProtocal("username");//定义数据库用户名
// String password=loadProtocal("password");//定义数据库密码
String driverClassName="oracle.jdbc.driver.OracleDriver";//定义驱动
String url="jdbc:oracle:thin:@192.168.1.8:1521:ORA9IDB";
String userName="rcfw0301";//定义数据库用户名
String password="rcfw0301";//定义数据库密码
Class.forName(driverClassName);
// 建立连接
Connection con = DriverManager.getConnection(url,userName,password);
// 创建状态
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from user_tables");//
while(rs.next()){
System.out.println("表名:" + rs.getString(1));
tableNameList.add(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
}
catch(Exception err)
{
System.out.println("xxx"+err.getMessage());
}
return tableNameList;
}
public static List getColName(String tableName)
{
List colNameList=new ArrayList();
try
{
// String driverClassName=loadProtocal("driverClassName");//定义驱动
// String url=loadProtocal("url");;//定义连接字符串
// String userName=loadProtocal("username");//定义数据库用户名
// String password=loadProtocal("password");//定义数据库密码
String driverClassName="oracle.jdbc.driver.OracleDriver";//定义驱动
String url="jdbc:oracle:thin:@192.168.1.8:1521:ORA9IDB";
String userName="rcfw0301";//定义数据库用户名
String password="rcfw0301";//定义数据库密码
Class.forName(driverClassName);
// 建立连接
Connection con = DriverManager.getConnection(url,userName,password);
// 创建状态
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from " +tableName);//
ResultSetMetaData rsMeta=rs.getMetaData();
int count=rsMeta.getColumnCount();//此名执行正确
for (int i = 1; i <= count; i++) {
System.out.print("列名:" + rsMeta.getColumnName(i));
colNameList.add(rsMeta.getColumnName(i));
} rs.close(); stmt.close(); con.close(); } catch(Exception err) { System.out.println(err.getMessage()); } return colNameList; }