public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException { if (null != rs && rs.next()) return rs.getBoolean(1); return null; }
@Override public UserDetails mapRow(ResultSet rs, int rowNum) throws SQLException { String username = rs.getString(1); String password = rs.getString(2); boolean enabled = rs.getBoolean(3); return new User(username, password, enabled, true, true, true, AuthorityUtils.NO_AUTHORITIES); }
/** * 初始化 * * @param tableName 表名 * @param columnMetaRs 列的meta ResultSet * @throws SQLException SQL执行异常 */ public void init(String tableName, ResultSet columnMetaRs) throws SQLException { this.tableName = tableName; this.name = columnMetaRs.getString("COLUMN_NAME"); this.type = columnMetaRs.getInt("DATA_TYPE"); this.size = columnMetaRs.getInt("COLUMN_SIZE"); this.isNullable = columnMetaRs.getBoolean("NULLABLE"); this.comment = columnMetaRs.getString("REMARKS"); }
static Migration convertPipelineSelectionsToFilters() { return (cxn) -> { if (!required(cxn)) return; try (Statement s = cxn.createStatement()) { final ResultSet rs = s.executeQuery("SELECT id, selections, isblacklist FROM pipelineselections WHERE version = 0"); while (rs.next()) { perform(cxn, rs.getLong(ID), rs.getString(SELECTIONS), rs.getBoolean(BLACKLIST)); } } }; }
private String getDefaultSchemaName(DatabaseMetaData meta) { String defaultSchemaName = ""; try { if (isOracle) { return meta.getUserName(); } else if (isPostgreSQL) { return "public"; } else if (isMySQL) { return ""; } else if (isDerby) { return StringUtils.toUpperEnglish(meta.getUserName()); } else if (isFirebird) { return null; } ResultSet rs = meta.getSchemas(); int index = rs.findColumn("IS_DEFAULT"); while (rs.next()) { if (rs.getBoolean(index)) { defaultSchemaName = rs.getString("TABLE_SCHEM"); } } } catch (SQLException e) { // IS_DEFAULT not found } return defaultSchemaName; }
@Override public DefaultColumnInfo map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException { final String tableName = r.getString("table_name"); final String columnName = r.getString("column_name"); final Long scale = r.getLong("numeric_scale"); final Long precision = r.getLong("numeric_precision"); // Special handling for PostgreSQL - the implementation of AbstractJdbc2ResultSet#getBoolean doesn't support YES/NO final String isNullableString = r.getString("is_nullable"); final boolean isNullable; if ("YES".equalsIgnoreCase(isNullableString)) { isNullable = true; } else if ("NO".equalsIgnoreCase(isNullableString)) { isNullable = false; } else { isNullable = r.getBoolean("is_nullable"); } final Long maximumLength = r.getLong("character_maximum_length"); final String dataType = r.getString("data_type"); return new DefaultColumnInfo(tableName, columnName, scale, precision, isNullable, maximumLength, dataType); } }
break; case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default:
@Override public List<Executor> handle(final ResultSet rs) throws SQLException { if (!rs.next()) { return Collections.emptyList(); } final List<Executor> executors = new ArrayList<>(); do { final int id = rs.getInt(1); final String host = rs.getString(2); final int port = rs.getInt(3); final boolean active = rs.getBoolean(4); final Executor executor = new Executor(id, host, port, active); executors.add(executor); } while (rs.next()); return executors; } }
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException { List<Boolean> list = new LinkedList<Boolean>(); if (null != rs && rs.next()) list.add(rs.getBoolean(1)); boolean[] array = new boolean[list.size()]; for (int i = 0; i < array.length; i++) { array[i] = list.get(i); } return array; }
@AfterClass public static void tearDownConnection() throws SQLException { final ResultSet util = connection.createStatement().executeQuery( "DROP VIEW " + VIEW_NAME + "" ); assertTrue( util.next() ); assertTrue("Error dropping temporary test-columns view " + VIEW_NAME + ": " + util.getString( 2 ), util.getBoolean( 1 ) ); connection.close(); }
/** * 初始化 * * @param tableName 表名 * @param columnMetaRs 列的meta ResultSet * @throws SQLException SQL执行异常 */ public void init(String tableName, ResultSet columnMetaRs) throws SQLException { this.tableName = tableName; this.name = columnMetaRs.getString("COLUMN_NAME"); this.type = columnMetaRs.getInt("DATA_TYPE"); this.size = columnMetaRs.getInt("COLUMN_SIZE"); this.isNullable = columnMetaRs.getBoolean("NULLABLE"); this.comment = columnMetaRs.getString("REMARKS"); }
@Override public UserDetails mapRow(ResultSet rs, int rowNum) throws SQLException { String username = rs.getString(1); String password = rs.getString(2); boolean enabled = rs.getBoolean(3); return new User(username, password, enabled, true, true, true, AuthorityUtils.NO_AUTHORITIES); }
protected <V> V getScalarFromResultSet(ResultSet rs, Class<V> returnType) throws SQLException { Object value = null; if (Integer.class == returnType) { value = rs.getInt(1); } else if (Long.class == returnType) { value = rs.getLong(1); } else if (String.class == returnType) { value = rs.getString(1); } else if (Boolean.class == returnType) { value = rs.getBoolean(1); } else if (Double.class == returnType) { value = rs.getDouble(1); } else if (Date.class == returnType) { value = rs.getDate(1); } else if (Timestamp.class == returnType) { value = rs.getTimestamp(1); } else { value = rs.getObject(1); } if (null == value) { throw new NullPointerException("Cannot get value from ResultSet of type " + returnType.getName()); } return returnType.cast(value); }
@Override public Void call() throws Exception { ResultSet rs0 = stmt.executeQuery("select 'qwe'"); assert rs0.next(); assert rs0.getBoolean(1); return null; } }, SQLException.class, "Cannot convert to boolean: qwe");
@AfterClass public static void tearDownConnection() throws SQLException { final ResultSet util = connection.createStatement().executeQuery( "DROP VIEW " + VIEW_NAME + "" ); assertTrue( util.next() ); assertTrue( "Error dropping temporary test-columns view " + VIEW_NAME + ": " + util.getString( 2 ), util.getBoolean( 1 ) ); connection.close(); }
static TypeInfoMetaData of(ResultSet rs) throws SQLException { final String sqlTypeName = rs.getString("TYPE_NAME"); final int javaSqlTypeInt = rs.getInt("DATA_TYPE"); final int precision = rs.getInt("PRECISION"); final short nullable = rs.getShort("NULLABLE"); final boolean unsigned = rs.getBoolean("UNSIGNED_ATTRIBUTE"); return of(sqlTypeName, javaSqlTypeInt, precision, precision, nullable, unsigned); }
@Override public ColumnIndex convert(ResultSet rs) throws SQLException { return new ColumnIndex(rs.getString(1), rs.getBoolean(2), rs.getString(3)); } }
while (rs.next()) { out.print(rs.getString(columnIndex)); } else if (type == Types.DATE) { Date date = rs.getDate(columnIndex); boolean value = rs.getBoolean(columnIndex); if (rs.wasNull()) { out.print("null"); boolean value = rs.getBoolean(columnIndex); if (rs.wasNull()) { out.print("null"); int value = rs.getInt(columnIndex); if (rs.wasNull()) { out.print("null"); long value = rs.getLong(columnIndex); if (rs.wasNull()) { out.print("null"); Object object = rs.getString(columnIndex);
@Override public Void call() throws Exception { ResultSet rs0 = stmt.executeQuery("select ''"); assert rs0.next(); assert rs0.getBoolean(1); return null; } }, SQLException.class, "Cannot convert to boolean: ");
@AfterClass public static void tearDownConnection() throws SQLException { ResultSet util = connection.createStatement().executeQuery( "DROP VIEW " + VIEW_NAME + "" ); assertTrue( util.next() ); assertTrue( "Error dropping temporary test-columns view " + VIEW_NAME + ": " + util.getString( 2 ), util.getBoolean( 1 ) ); connection.close(); }