本文整理汇总了Java中java.sql.ResultSetMetaData.isNullable方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSetMetaData.isNullable方法的具体用法?Java ResultSetMetaData.isNullable怎么用?Java ResultSetMetaData.isNullable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.ResultSetMetaData
的用法示例。
在下文中一共展示了ResultSetMetaData.isNullable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isEqualsTo
import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
boolean isEqualsTo(ResultSetMetaData metadata, int colNum) throws SQLException {
return
metadata.getCatalogName(colNum).equals(InfoSchemaConstants.IS_CATALOG_NAME) &&
metadata.getSchemaName(colNum).isEmpty() &&
metadata.getTableName(colNum).isEmpty() &&
metadata.getColumnName(colNum).equals(columnName) &&
metadata.getColumnLabel(colNum).equals(columnName) &&
metadata.getColumnType(colNum) == type &&
metadata.isNullable(colNum) == nullable &&
// There is an existing bug where query results doesn't contain the precision for VARCHAR field.
//metadata.getPrecision(colNum) == precision &&
metadata.getScale(colNum) == scale &&
metadata.isSigned(colNum) == signed &&
metadata.getColumnDisplaySize(colNum) == displaySize &&
metadata.getColumnClassName(colNum).equals(className) &&
metadata.isSearchable(colNum) &&
metadata.isAutoIncrement(colNum) == false &&
metadata.isCaseSensitive(colNum) == false &&
metadata.isReadOnly(colNum) &&
metadata.isWritable(colNum) == false &&
metadata.isDefinitelyWritable(colNum) == false &&
metadata.isCurrency(colNum) == false;
}
示例2: toFlag
import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public static int toFlag(ResultSetMetaData metaData, int column)
throws SQLException {
int flags = 0;
if (metaData.isNullable(column) == 1) {
flags |= 1;
}
if (metaData.isSigned(column)) {
flags |= 16;
}
if (metaData.isAutoIncrement(column)) {
flags |= 128;
}
return flags;
}
示例3: toString
import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
private static String toString(ResultSetMetaData metadata, int colNum) throws SQLException {
return "ResultSetMetaData(" + colNum + ")[" +
"columnName='" + metadata.getColumnName(colNum) + '\'' +
", type='" + metadata.getColumnType(colNum) + '\'' +
", nullable=" + metadata.isNullable(colNum) +
", displaySize=" + metadata.getColumnDisplaySize(colNum) +
", precision=" + metadata.getPrecision(colNum) +
", scale=" + metadata.getScale(colNum) +
", signed=" + metadata.isSigned(colNum) +
", className='" + metadata.getColumnClassName(colNum) + '\'' +
']';
}
示例4: validateResultSet
import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
private MultiShardException validateResultSet(ResultSet r,
ShardLocation loc) throws SQLException {
if (r.isClosed()) {
// ResultSet is already closed. Hence adding an exception in its place.
return new MultiShardException(loc, new MultiShardResultSetClosedException(
String.format("The result set for '%1$s' was closed and could not be added.", loc.getDatabase())));
}
ResultSetMetaData m = r.getMetaData();
if (m == null || m.getColumnCount() == 0) {
// ResultSet does not have proper metadata to read.
return new MultiShardException(loc, new MultiShardResultSetInternalException(
String.format("The result set for '%1$s' does not have proper metadata to read and could not be added.", loc.getDatabase())));
}
if (this.schemaComparisonTemplate == null) {
this.schemaComparisonTemplate = r.getMetaData();
return null;
}
for (int i = 1; i <= m.getColumnCount(); i++) {
// Get the designated column's name.
String expectedName = this.schemaComparisonTemplate.getColumnName(i);
String actualName = m.getColumnName(i);
if (!Objects.equals(expectedName, actualName)) {
return new MultiShardException(loc, new MultiShardSchemaMismatchException(loc,
String.format("Expected schema column name %1$s, but encountered schema column name %2$s.", expectedName, actualName)));
}
// Retrieves the designated column's SQL type.
if (!Objects.equals(this.schemaComparisonTemplate.getColumnType(i), m.getColumnType(i))) {
return new MultiShardException(loc,
new MultiShardSchemaMismatchException(loc,
String.format("Mismatched SQL type values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
this.schemaComparisonTemplate.getColumnTypeName(i), m.getColumnTypeName(i))));
}
// Get the designated column's specified column size.
int expectedPrecision = this.schemaComparisonTemplate.getPrecision(i);
int actualPrecision = m.getPrecision(i);
if (!Objects.equals(expectedPrecision, actualPrecision)) {
return new MultiShardException(loc,
new MultiShardSchemaMismatchException(loc,
String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
expectedPrecision, actualPrecision)));
}
// Indicates the nullability of values in the designated column.
int expectedNullableValue = this.schemaComparisonTemplate.isNullable(i);
int actualNullableValue = m.isNullable(i);
if (!Objects.equals(expectedNullableValue, actualNullableValue)) {
return new MultiShardException(loc,
new MultiShardSchemaMismatchException(loc,
String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
NullableValue.forValue(expectedNullableValue), NullableValue.forValue(actualNullableValue))));
}
}
return null;
}
示例5: setTable
import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
* Configures this class, by reading in the structure of the log-table
* Throws an exception, if an database-error occurs !
*
* @param _table
* Description of Parameter
* @exception Exception
* Description of Exception
*/
public void setTable(String _table) throws Exception {
if (isconfigured) { return; }
if (poolConnectionHandler != null) {
con = poolConnectionHandler.getConnection();
if (!isConnected()) { throw new Exception(
"JDBCLogger::setTable(), Given connection isnt connected to database !"); }
}
//Fill logcols with META-informations of the table-columns
stmt = this.createUpdatableStatement();
rs = stmt.executeQuery("SELECT " + _table + ".* FROM " + _table + " WHERE 1 = 2");
JDBCLogColumn logcol;
ResultSetMetaData rsmd = rs.getMetaData();
num = rsmd.getColumnCount();
logcols = new ArrayList(num);
for (int i = 1; i <= num; i++) {
logcol = new JDBCLogColumn();
logcol.name = rsmd.getColumnName(i).toUpperCase();
logcol.sqlType = rsmd.getColumnType(i);
logcol.type = rsmd.getColumnTypeName(i);
logcol.nullable = (rsmd.isNullable(i) == ResultSetMetaData.columnNullable);
logcol.isWritable = rsmd.isWritable(i);
if (!logcol.isWritable) {
logcol.ignore = true;
}
logcols.add(logcol);
}
table = _table;
rs.close();
stmt.close();
freeConnection();
isconfigured = true;
}
示例6: findMultiColumnInfos
import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public List<ColumnInfo> findMultiColumnInfos(String dbInfoId, String sql) throws Exception {
if (!StringUtils.hasText(sql)) {
return null;
}
DataSource ds = this.getDataSourceByDbInfoId(dbInfoId);
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
conn = DataSourceUtils.getConnection(ds);
st = conn.createStatement();
rs = st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int count = rsmd.getColumnCount();
List<ColumnInfo> columnNames = new ArrayList<ColumnInfo>();
ColumnInfo columnInfo = null;
for (int i = 1; i <= count; i++) {
columnInfo = new ColumnInfo();
columnInfo.setColumnName(rsmd.getColumnLabel(i));
columnInfo.setColumnType(rsmd.getColumnTypeName(i));
columnInfo.setTableName(rsmd.getTableName(i));
if (rsmd.getPrecision(i) > 0 && !columnInfo.getColumnType().equals("DATETIME") && !columnInfo.getColumnType().equals("TIMESTAMP") && !columnInfo.getColumnType().equals("DATE")) {
columnInfo.setColumnSize(String.valueOf(rsmd.getPrecision(i)));
}
if (rsmd.getScale(i) > 0 && !columnInfo.getColumnType().equals("DATETIME") && !columnInfo.getColumnType().equals("TIMESTAMP") && !columnInfo.getColumnType().equals("DATE")) {
columnInfo.setColumnSize(columnInfo.getColumnSize() + "," + rsmd.getScale(i));
}
int flagI = rsmd.isNullable(i);
if (flagI == 0) {
columnInfo.setIsnullAble(false);
} else {
columnInfo.setIsnullAble(true);
}
columnNames.add(columnInfo);
}
return columnNames;
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(st);
JdbcUtils.closeConnection(conn);
}
}