⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlresultsetmetadata.java

📁 JAVA编程百例书中各章节的所有例子的源代码,包括套接字编程
💻 JAVA
字号:
package ch03.section09;

import java.sql.*;

public class SQLResultSetMetaData
    implements java.sql.ResultSetMetaData {
  private SResultSet tsql;
  public SQLResultSetMetaData(SResultSet result) {
    tsql = result;
  }

  public int getColumnCount() throws SQLException {
    return tsql.numcols();
  }

  public boolean isAutoIncrement(int column) throws SQLException {
    return false;
  }

  public boolean isCaseSensitive(int column) throws SQLException {
    return true;
  }

  public boolean isSearchable(int column) throws SQLException {
    return true;
  }

  public boolean isCurrency(int column) throws SQLException {
    return false;
  }

  public int isNullable(int column) throws SQLException {
    return columnNoNulls;
  }

  public boolean isSigned(int column) throws SQLException {
    return true;
  }

  public int getColumnDisplaySize(int column) throws SQLException {
    SColumn col = tsql.columnAtIndex(column - 1);
    return col.size;

  }

  public String getColumnLabel(int column) throws SQLException {
    SColumn col = tsql.columnAtIndex(column - 1);
    return (col.table + "." + col.name);
  }

  //SColumn的名称
  public String getColumnName(int column) throws SQLException {
    SColumn col = tsql.columnAtIndex(column - 1);
    return col.name;
  }

  public String getSchemaName(int column) throws SQLException {
    return "";
  }

  public int getPrecision(int column) throws SQLException {
    throw new SQLException("tinySQL does not support precision.");
  }

  public int getScale(int column) throws SQLException {
    throw new SQLException("does not support scale.");
  }

  //获取TABLE的名称
  public String getTableName(int column) throws SQLException {
    SColumn col = tsql.columnAtIndex(column - 1);
    return col.table;
  }

  public String getCatalogName(int column) throws SQLException {
    throw new SQLException(" does not support catalogues.");
  }

  // 返回列的类型
  public int getColumnType(int column) throws SQLException {

    SColumn col = tsql.columnAtIndex(column - 1);
    if (col.type.equals("CHAR")) {
      return Types.CHAR;
    }
    if (col.type.equals("NUMERIC")) {
      return Types.INTEGER;
    }
    throw new SQLException("Unknown data type.");
  }

  // 返回列的类型名称
  public String getColumnTypeName(int column) throws SQLException {
    switch (getColumnType(column)) {
      case Types.INTEGER:
        return "INT";
      case Types.CHAR:
        return "CHAR";
      default:
        return "NULL";
    }
  }

  public boolean isReadOnly(int column) throws SQLException {
    return false;
  }

  public boolean isWritable(int column) throws SQLException {
    return true;
  }

  public boolean isDefinitelyWritable(int column) throws SQLException {
    return true;
  }

  public String getColumnClassName(int column) {
    return null;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -