Package com.xiaoleilu.hutool.db.meta

Examples of com.xiaoleilu.hutool.db.meta.Table


   * @param tableName 表名
   * @return Table对象
   */
  @SuppressWarnings("resource")
  public static Table getTableMeta(DataSource ds, String tableName) {
    final Table table = Table.create(tableName);
    Connection conn = null;
    ResultSet rs = null;
    try {
      conn = ds.getConnection();
      final DatabaseMetaData metaData = conn.getMetaData();
      //获得主键
      rs = metaData.getPrimaryKeys(conn.getCatalog(), null, tableName);
      while(rs.next()) {
        table.addPk("COLUMN_NAME");
      }
     
      //获得列
      rs = metaData.getColumns(conn.getCatalog(), null, tableName, null);
      while(rs.next()) {
        table.setColumn(Column.create(tableName, rs));
      }
    } catch (Exception e) {
      throw new UtilException("Get columns error!", e);
    }finally {
      close(rs, conn);
View Full Code Here


    Log.info("{}", tableNames);

    /*
     * 获得表结构 表结构封装为一个表对象,里面有Column对象表示一列,列中有列名、类型、大小、是否允许为空等信息
     */
    Table table = DbUtil.getTableMeta(ds, TABLE_NAME);
    Log.info("{}", table);
  }
View Full Code Here

TOP

Related Classes of com.xiaoleilu.hutool.db.meta.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.