?? sqlresultsetmetadata.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 + -