For IntelliJ IDEA and
Android Studio


private void myMethod () {ResultSet r =
PreparedStatement ps;ps.executeQuery()
Statement stmt;stmt.executeQuery(sql)
Statement statement;statement.getResultSet()
- AI code suggestions by Codota
}
@Override public Table map(int index, ResultSet r, StatementContext ctx) throws SQLException { return new Table( r.getLong("table_id"), getOptionalLong(r, "distribution_id"), Optional.ofNullable(r.getString("distribution_name")), getOptionalInt(r, "bucket_count"), getOptionalLong(r, "temporal_column_id"), r.getBoolean("organization_enabled")); } }
@Override public TableMetadataRow map(int index, ResultSet rs, StatementContext context) throws SQLException { return new TableMetadataRow( rs.getLong("table_id"), rs.getString("schema_name"), rs.getString("table_name"), getOptionalLong(rs, "temporal_column_id"), Optional.ofNullable(rs.getString("distribution_name")), getOptionalInt(rs, "bucket_count"), rs.getBoolean("organization_enabled")); } }
private static Object getValue(ResultSet resultSet, Type type, String columnName, JDBCType jdbcType) throws SQLException { switch (jdbcType) { case BOOLEAN: return resultSet.getBoolean(columnName); case INTEGER: return resultSet.getInt(columnName); case BIGINT: return resultSet.getLong(columnName); case DOUBLE: return resultSet.getDouble(columnName); case VARBINARY: return wrappedBuffer(resultSet.getBytes(columnName)).toStringUtf8(); } throw new IllegalArgumentException("Unhandled type: " + type); }
@Override public TableColumn map(int index, ResultSet r, StatementContext ctx) throws SQLException { SchemaTableName table = new SchemaTableName( r.getString("schema_name"), r.getString("table_name")); String typeName = r.getString("data_type"); Type type = typeManager.getType(parseTypeSignature(typeName)); checkArgument(type != null, "Unknown type %s", typeName); return new TableColumn( table, r.getString("column_name"), type, r.getLong("column_id"), getOptionalInt(r, "bucket_ordinal_position"), getOptionalInt(r, "sort_ordinal_position"), r.getBoolean("temporal")); } }
private List<JobExecutionEvent> getJobExecutionEvents(final Condition condition) { List<JobExecutionEvent> result = new LinkedList<>(); try ( Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = createDataPreparedStatement(conn, TABLE_JOB_EXECUTION_LOG, FIELDS_JOB_EXECUTION_LOG, condition); ResultSet resultSet = preparedStatement.executeQuery() ) { while (resultSet.next()) { JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5), JobExecutionEvent.ExecutionSource.valueOf(resultSet.getString(6)), Integer.valueOf(resultSet.getString(7)), new Date(resultSet.getTimestamp(8).getTime()), resultSet.getTimestamp(9) == null ? null : new Date(resultSet.getTimestamp(9).getTime()), resultSet.getBoolean(10), new JobExecutionEventThrowable(null, resultSet.getString(11)) ); result.add(jobExecutionEvent); } } catch (final SQLException ex) { // TODO 记录失败直接输出日志,未来可考虑配置化 log.error("Fetch JobExecutionEvent from DB error:", ex); } return result; }
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; }
result = getCurrentResultSet().getObject(columnLabel); } else if (boolean.class == type) { result = getCurrentResultSet().getBoolean(columnLabel); } else if (byte.class == type) { result = getCurrentResultSet().getByte(columnLabel); result = getCurrentResultSet().getShort(columnLabel); } else if (int.class == type) { result = getCurrentResultSet().getInt(columnLabel); } else if (long.class == type) { result = getCurrentResultSet().getLong(columnLabel); } else if (float.class == type) { result = getCurrentResultSet().getFloat(columnLabel); result = getCurrentResultSet().getDouble(columnLabel); } else if (String.class == type) { result = getCurrentResultSet().getString(columnLabel); } else if (BigDecimal.class == type) { result = getCurrentResultSet().getBigDecimal(columnLabel); result = getCurrentResultSet().getTime(columnLabel); } else if (Timestamp.class == type) { result = getCurrentResultSet().getTimestamp(columnLabel); } else if (URL.class == type) { result = getCurrentResultSet().getURL(columnLabel);
try (ResultSet resultSet = preparedStatement.executeQuery()) { List<List<Column>> rows = Lists.newArrayList(); while (resultSet.next()) { ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); row.add(new Column<Short>(columnLabel, resultSet.getShort(columnLabel), columnType)); } else if (columnJavaType.equals(Boolean.class)) { row.add(new Column<Boolean>(columnLabel, resultSet.getBoolean(columnLabel), columnType)); } else if (columnJavaType.equals(byte[].class)) { row.add(new Column<byte[]>(columnLabel, resultSet.getBytes(columnLabel), columnType)); } else if (columnJavaType.equals(Long.class)) { row.add(new Column<Long>(columnLabel, resultSet.getLong(columnLabel), columnType)); } else if (columnJavaType.equals(Date.class)) { row.add(new Column<Date>(columnLabel, resultSet.getDate(columnLabel), columnType)); row.add(new Column<Time>(columnLabel, resultSet.getTime(columnLabel), columnType)); } else if (columnJavaType.equals(Timestamp.class)) { row.add(new Column<Timestamp>(columnLabel, resultSet.getTimestamp(columnLabel), columnType)); } else { throw new RuntimeException("type = " + columnType + " for column " + columnLabel + " not supported.");
booleans[i] = resultSet.getBoolean(i + 1); nulls[i] = resultSet.wasNull(); if (!nulls[i]) { longs[i] = resultSet.getLong(i + 1); nulls[i] = resultSet.wasNull(); if (!nulls[i]) { long value = resultSet.getLong(i + 1); nulls[i] = resultSet.wasNull(); strings[i] = nulls[i] ? null : format("%016x", value); String value = resultSet.getString(i + 1); nulls[i] = resultSet.wasNull(); strings[i] = nulls[i] ? null : value;
throws SQLException long id = resultSet.getLong("resource_group_id"); ResourceGroupNameTemplate nameTemplate = new ResourceGroupNameTemplate(resultSet.getString("name")); String softMemoryLimit = resultSet.getString("soft_memory_limit"); int maxQueued = resultSet.getInt("max_queued"); Optional<Integer> softConcurrencyLimit = Optional.of(resultSet.getInt("soft_concurrency_limit")); if (resultSet.wasNull()) { softConcurrencyLimit = Optional.empty(); int hardConcurrencyLimit = resultSet.getInt("hard_concurrency_limit"); Optional<String> schedulingPolicy = Optional.ofNullable(resultSet.getString("scheduling_policy")); Optional<Integer> schedulingWeight = Optional.of(resultSet.getInt("scheduling_weight")); if (resultSet.wasNull()) { schedulingWeight = Optional.empty(); Optional<Boolean> jmxExport = Optional.of(resultSet.getBoolean("jmx_export")); if (resultSet.wasNull()) { jmxExport = Optional.empty(); Optional<String> softCpuLimit = Optional.ofNullable(resultSet.getString("soft_cpu_limit")); Optional<String> hardCpuLimit = Optional.ofNullable(resultSet.getString("hard_cpu_limit")); Optional<Long> parentId = Optional.of(resultSet.getLong("parent")); if (resultSet.wasNull()) { parentId = Optional.empty();
final ResultSet resultSet = metaData.getTypeInfo(); try { while ( resultSet.next() ) { typeInfoSet.add( new TypeInfo( resultSet.getString( "TYPE_NAME" ), resultSet.getInt( "DATA_TYPE" ), interpretCreateParams( resultSet.getString( "CREATE_PARAMS" ) ), resultSet.getBoolean( "UNSIGNED_ATTRIBUTE" ), resultSet.getInt( "PRECISION" ), resultSet.getShort( "MINIMUM_SCALE" ), resultSet.getShort( "MAXIMUM_SCALE" ), resultSet.getBoolean( "FIXED_PREC_SCALE" ), resultSet.getString( "LITERAL_PREFIX" ), resultSet.getString( "LITERAL_SUFFIX" ), resultSet.getBoolean( "CASE_SENSITIVE" ), TypeSearchability.interpret( resultSet.getShort( "SEARCHABLE" ) ), TypeNullability.interpret( resultSet.getShort( "NULLABLE" ) )
if (rs.next()) { this.autoCommit = rs.getBoolean(1); if (this.autoCommit != true) { overrideDefaultAutocommit = true;
while (rs.next()) { String name = rs.getString("INDEX_NAME"); IndexInfo info = indexMap.get(name); if (info == null) { int t = rs.getInt("TYPE"); String type; if (t == DatabaseMetaData.tableIndexClustered) { info = new IndexInfo(); info.name = name; type = (rs.getBoolean("NON_UNIQUE") ? "${text.tree.nonUnique}" : "${text.tree.unique}") + type; info.type = type; info.columns = rs.getString("COLUMN_NAME"); indexMap.put(name, info); info.columns += ", " + rs.getString("COLUMN_NAME");
Type type = types.get(i - 1); if (BOOLEAN.equals(type)) { boolean booleanValue = resultSet.getBoolean(i); if (resultSet.wasNull()) { row.add(null); int intValue = resultSet.getInt(i); if (resultSet.wasNull()) { row.add(null); long longValue = resultSet.getLong(i); if (resultSet.wasNull()) { row.add(null); String stringValue = resultSet.getString(i); if (resultSet.wasNull()) { row.add(null); String stringValue = resultSet.getString(i); if (resultSet.wasNull()) { row.add(null); Timestamp timestampValue = resultSet.getTimestamp(i); if (resultSet.wasNull()) { row.add(null);
boolean value = rs.getBoolean(columnIndex); v = rs.wasNull() ? (Value) ValueNull.INSTANCE : ValueBoolean.get(value); Timestamp value = rs.getTimestamp(columnIndex); v = value == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(value); int value = rs.getInt(columnIndex); v = rs.wasNull() ? (Value) ValueNull.INSTANCE : ValueInt.get(value); long value = rs.getLong(columnIndex); v = rs.wasNull() ? (Value) ValueNull.INSTANCE : ValueLong.get(value); String s = rs.getString(columnIndex); v = (s == null) ? (Value) ValueNull.INSTANCE : ValueStringIgnoreCase.get(s); String s = rs.getString(columnIndex); v = (s == null) ? (Value) ValueNull.INSTANCE : ValueStringFixed.get(s); String s = rs.getString(columnIndex); v = (s == null) ? (Value) ValueNull.INSTANCE : ValueString.get(s);
supportsMixedCaseIdentifiers = meta.supportsMixedCaseIdentifiers(); ResultSet rs = meta.getTables(null, originalSchema, originalTable, null); if (rs.next() && rs.next()) { throw DbException.get(ErrorCode.SCHEMA_NAME_MUST_MATCH, originalTable); HashMap<String, Column> columnMap = new HashMap<>(); String catalog = null, schema = null; while (rs.next()) { String thisCatalog = rs.getString("TABLE_CAT"); if (catalog == null) { catalog = thisCatalog; String thisSchema = rs.getString("TABLE_SCHEM"); if (schema == null) { schema = thisSchema; break; list.clear(); boolean unique = !rs.getBoolean("NON_UNIQUE"); indexType = unique ? IndexType.createUnique(false, false) : IndexType.createNonUnique(false);
result = getCurrentResultSet().getObject(columnIndex); } else if (boolean.class == type) { result = getCurrentResultSet().getBoolean(columnIndex); } else if (byte.class == type) { result = getCurrentResultSet().getByte(columnIndex); result = getCurrentResultSet().getShort(columnIndex); } else if (int.class == type) { result = getCurrentResultSet().getInt(columnIndex); } else if (long.class == type) { result = getCurrentResultSet().getLong(columnIndex); } else if (float.class == type) { result = getCurrentResultSet().getFloat(columnIndex); result = getCurrentResultSet().getDouble(columnIndex); } else if (String.class == type) { result = getCurrentResultSet().getString(columnIndex); } else if (BigDecimal.class == type) { result = getCurrentResultSet().getBigDecimal(columnIndex); result = getCurrentResultSet().getTime(columnIndex); } else if (Timestamp.class == type) { result = getCurrentResultSet().getTimestamp(columnIndex); } else if (URL.class == type) { result = getCurrentResultSet().getURL(columnIndex);
@Override public ColumnIndex convert(ResultSet rs) throws SQLException { return new ColumnIndex(rs.getString(1), rs.getBoolean(2), rs.getString(3)); } }
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; }
private void assertIndexImpl(String tableName, String indexName, boolean expectedUnique, String expectedColumn, String... expectedSecondaryColumns) { try (Connection connection = getConnection(); ResultSet rs = connection.getMetaData().getIndexInfo(null, null, tableName.toUpperCase(Locale.ENGLISH), false, false)) { List<String> onColumns = new ArrayList<>(); while (rs.next()) { if (indexName.equalsIgnoreCase(rs.getString("INDEX_NAME"))) { assertThat(rs.getBoolean("NON_UNIQUE")).isEqualTo(!expectedUnique); int position = rs.getInt("ORDINAL_POSITION"); onColumns.add(position - 1, rs.getString("COLUMN_NAME").toLowerCase(Locale.ENGLISH)); } } assertThat(asList(expectedColumn, expectedSecondaryColumns)).isEqualTo(onColumns); } catch (SQLException e) { throw new IllegalStateException("Fail to check index", e); } }