lovefan
发贴: 18
积分: 0
|
于 2004-09-24 15:04
获取一个数据库中存在哪些表
import java.io.*; import java.sql.*; import java.util.*;
import com.lovefan.db.*; import com.lovefan.util.*;
public class ListAllTables { private ArrayList arrTables = new ArrayList(); private DBConnectionManager dbcm = DBConnectionManager.getInstance(); public ListAllTables() { String tmpTableName = null; try { Connection conn = dbcm.getConnection(); DatabaseMetaData dmd = conn.getMetaData(); ResultSet rsTables = dmd.getTables(null, null, null, null); while (rsTables.next()) { tmpTableName = rsTables.getString(3); if(tmpTableName.startsWith(GenBeanConst.tableHead)){ System.out.println(tmpTableName); } }
rsTables.close(); dbcm.freeConnection(conn);
} catch (Exception ex) { ex.printStackTrace(); }
} public static void main(String[] args) { ListAllTables lat=new ListAllTables(); } }
|