下个PHP做的admin,看看原吗蚂,他从那里取出的所有表

解决方案 »

  1.   

    忘了说了,用jsp语言实现!大家帮忙!
      

  2.   

    大家帮忙啊。怎么取得jsp单个库中所有表的名称?还有单个表中所有列的名称?
      

  3.   

    JSP中取出表名?好象有点难吧!
    看来我得查查书才行!
      

  4.   

    用sql语句,"show databases",然后getString(1)
      

  5.   

    取出所有库是show databases列出当前库中所有表名是show tables
      

  6.   

    show databases 返回的什么类型?resultset 还是 array?
      

  7.   

    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Hashtable;
    import java.util.Vector;public class Database
    {
        private Connection connection;
        private String driver;
        private String url;
        private String username;
        private String password;
        private DatabaseMetaData _metaData;
        
        private Database() {
    /* empty */
        }
        
        public Database(String driver, String url, String username,
        String password) {
    this.driver = driver;
    this.url = url;
    this.username = username;
    this.password = password;
        }
        
        public void makeConnection() throws ClassNotFoundException, SQLException {
    Class.forName(driver);
    connection = DriverManager.getConnection(url, username, password);
        }
        
        public Connection getConnection() {
    return connection;
        }
        
        public DatabaseMetaData getTableMetaData() throws SQLException {
    _metaData = connection.getMetaData();
    System.out.println("");
    System.out.println("Database & Driver Information:");
    System.out.println("------------------------------");
    System.out.println("Database version : "
           .concat(_metaData.getDatabaseProductVersion()));
    System.out.println("Driver Name : ".concat(_metaData.getDriverName()));
    System.out.println
        (String.valueOf(new StringBuffer("Driver Version : ").append
    (_metaData.getDriverMajorVersion()).append
    (".")
    .append(_metaData.getDriverMinorVersion())));
    return _metaData;
        }
        
        public Vector getTableNames
    (String databaseType, String catalog, String schema,
     Hashtable hashOfTableNames)
    throws SQLException {
    Vector tableNames = new Vector();
    ResultSet tables = null;
    String[] tableTypes
        = { "TABLE", "VIEW", "ALIAS", "SYNONYM", "GLOBAL TEMPORARY",
    "LOCAL TEMPORARY", "SYSTEM TABLE" };
    tables = getTablesForDbType(databaseType, catalog, schema, tableTypes);
    if (databaseType.equals("NORMAL"))
        tables = _metaData.getTables(catalog, schema, "%", tableTypes);
    else if (databaseType.equals("SOLID")) {
        String query
    = "SELECT TABLE_SCHEMA,TABLE_TYPE,TABLE_NAME FROM TABLES";
        Statement stmt = connection.createStatement();
        tables = stmt.executeQuery(query);
    }
    String tableName = "";
    while (tables.next()) {
        tableName = tables.getString(3);
        String tableType = tables.getString(2);
        if (hashOfTableNames == null
    || hashOfTableNames.get(tableName) != null)
    tableNames.addElement(tableName);
    }
    tables.close();
    return tableNames;
        }
        
        private ResultSet getTablesForDbType
    (String databaseType, String catalog, String schema,
     String[] tableTypes)
    throws SQLException {
    ResultSet tables = null;
    if (databaseType.equals("NORMAL"))
        tables = _metaData.getTables(catalog, schema, "%", tableTypes);
    else if (databaseType.equals("SOLID")) {
        String query
    = "SELECT TABLE_SCHEMA,TABLE_TYPE,TABLE_NAME FROM TABLES";
        Statement stmt = connection.createStatement();
        tables = stmt.executeQuery(query);
    }
    return tables;
        }
        
        public Vector getTableNames() throws SQLException {
    String[] tableTypes
        = { "TABLE", "VIEW", "ALIAS", "SYNONYM", "GLOBAL TEMPORARY",
    "LOCAL TEMPORARY", "SYSTEM TABLE" };
    Vector tableNames = new Vector();
    ResultSet tables = null;
    String catalog = new String();
    String schema = new String();
    String databaseType = "NORMAL";
    if (databaseType.equals("NORMAL"))
        tables = _metaData.getTables(catalog, schema, "%", tableTypes);
    else if (databaseType.equals("SOLID")) {
        String query
    = "SELECT TABLE_SCHEMA,TABLE_TYPE,TABLE_NAME FROM TABLES";
        Statement stmt = connection.createStatement();
        tables = stmt.executeQuery(query);
    }
    String tableName = "";
    while (tables.next()) {
        tableName = tables.getString(3);
        String tableType = tables.getString(2);
        tableNames.addElement(tableName);
    }
    tables.close();
    return tableNames;
        }
    }这个给你看看,应该对你有所帮助的,要仔细看呀
    别忘了给分:)
      

  8.   

    VCVCVC(VC爱好者) ,多谢!虽然没有提供取得数据库名称功能,但已足够了!多谢: rootwuyu(wuyu) ;secretthing(玲珑) ,分送上!