本文整理汇总了Java中java.sql.ResultSet.getArray方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSet.getArray方法的具体用法?Java ResultSet.getArray怎么用?Java ResultSet.getArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.getArray方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatArrayColumn
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* Format the column as an java.sqlArray
*
* @param resultSet
* @param columnIndex
* @return
* @throws SQLException
* @throws IOException
*/
private String formatArrayColumn(ResultSet resultSet, int columnIndex)
throws SQLException, IOException {
Array array = resultSet.getArray(columnIndex);
Object[] objects = (Object[]) array.getArray();
String arrayStr = "{";
for (int i = 0; i < objects.length; i++) {
arrayStr += objects[i] + ",";
}
if (arrayStr.contains(",")) {
arrayStr = StringUtils.substringBeforeLast(arrayStr, ",");
}
arrayStr += "}";
return arrayStr;
/*
* ArrayHttp arrayHttp = new ArrayHttp(array); ArrayTransporter
* arrayTransporter = new ArrayTransporter(); String base64 =
* arrayTransporter.toBase64(arrayHttp); return base64;
*/
}
示例2: map
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Source map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
String resultSource = resultSet.getString("source");
if (StringUtils.isEmpty(resultSource)) {
return null;
}
Source source;
try {
source = new Source(new URL(resultSource));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Array tags = resultSet.getArray("tags");
source.setTags(tags == null
? Collections.emptyList()
: Arrays.asList((Object[]) tags.getArray()).stream().map(Object::toString).collect(Collectors.toList())
);
source.setFrontpage(resultSet.getBoolean("frontpage"));
return source;
}
示例3: nullSafeGet
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
throws HibernateException, SQLException {
Array array = rs.getArray(names[0]);
if (array == null) {
return null;
}
Long[] javaArray = (Long[]) array.getArray();
ArrayList<Long> result = new ArrayList<>();
Collections.addAll(result, javaArray); //do not use Arrays.asList(), that method returns a fake ArrayList
return result;
}
示例4: testArrays
import java.sql.ResultSet; //导入方法依赖的package包/类
@Test public void testArrays() throws SQLException {
ConnectionSpec.getDatabaseLock().lock();
try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
ResultSet resultSet =
stmt.executeQuery("select * from (values ('a', array['b', 'c']));");
assertTrue(resultSet.next());
assertEquals("a", resultSet.getString(1));
Array arr = resultSet.getArray(2);
assertTrue(arr instanceof ArrayImpl);
Object[] values = (Object[]) ((ArrayImpl) arr).getArray();
assertArrayEquals(new String[]{"b", "c"}, values);
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
示例5: convertAccessTypes
import java.sql.ResultSet; //导入方法依赖的package包/类
public static Set<Access> convertAccessTypes(ResultSet rs, String fieldName) throws SQLException {
Array accessTypeArray = rs.getArray(fieldName);
if (accessTypeArray != null) {
Integer[] accessTypeIds = (Integer[]) accessTypeArray.getArray();
int[] accessTypeIds2 = new int[accessTypeIds.length];
for (int i=0; i<accessTypeIds.length; i++) {
accessTypeIds2[i] = accessTypeIds[i];
}
return Access.getAccessTypes(accessTypeIds2);
} else {
return null;
}
}
示例6: canAcceptTest
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public boolean canAcceptTest(final JavaType type, final ResultSet rs, final int columnIndex,
final PropertyMapperManager mapperManager) throws SQLException {
java.sql.Array array = rs.getArray(columnIndex);
if (array == null) {
return true;
}
Object o = array.getArray();
return type.getRawType().isInstance(o);
}
示例7: getValue
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Object getValue(final JavaType type, final ResultSet rs, final int columnIndex,
final PropertyMapperManager mapperManager) throws SQLException {
java.sql.Array array = rs.getArray(columnIndex);
if (array == null) {
return null;
}
return array.getArray();
}
示例8: getNullableResult
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
Array array = rs.getArray(columnName);
return array == null ? null : array.getArray();
}
示例9: testGetArray
import java.sql.ResultSet; //导入方法依赖的package包/类
public void testGetArray(ResultSet resultSet) throws SQLException {
try {
resultSet.getArray(ordinal);
fail("Was expecting to throw SQLDataException");
} catch (Exception e) {
assertThat(e, isA((Class) SQLDataException.class)); // success
}
}
示例10: frame
import java.sql.ResultSet; //导入方法依赖的package包/类
/** Creates a frame containing a given number or unlimited number of rows
* from a result set. */
static Meta.Frame frame(StatementInfo info, ResultSet resultSet, long offset,
int fetchMaxRowCount, Calendar calendar, Optional<Meta.Signature> sig) throws SQLException {
final ResultSetMetaData metaData = resultSet.getMetaData();
final int columnCount = metaData.getColumnCount();
final int[] types = new int[columnCount];
Set<Integer> arrayOffsets = new HashSet<>();
for (int i = 0; i < types.length; i++) {
types[i] = metaData.getColumnType(i + 1);
if (Types.ARRAY == types[i]) {
arrayOffsets.add(i);
}
}
final List<Object> rows = new ArrayList<>();
// Meta prepare/prepareAndExecute 0 return 0 row and done
boolean done = fetchMaxRowCount == 0;
for (int i = 0; fetchMaxRowCount < 0 || i < fetchMaxRowCount; i++) {
final boolean hasRow;
if (null != info) {
hasRow = info.next();
} else {
hasRow = resultSet.next();
}
if (!hasRow) {
done = true;
resultSet.close();
break;
}
Object[] columns = new Object[columnCount];
for (int j = 0; j < columnCount; j++) {
columns[j] = getValue(resultSet, types[j], j, calendar);
if (arrayOffsets.contains(j)) {
// If we have an Array type, our Signature is lacking precision. We can't extract the
// component type of an Array from metadata, we have to update it as we're serializing
// the ResultSet.
final Array array = resultSet.getArray(j + 1);
// Only attempt to determine the component type for the array when non-null
if (null != array && sig.isPresent()) {
ColumnMetaData columnMetaData = sig.get().columns.get(j);
ArrayType arrayType = (ArrayType) columnMetaData.type;
SqlType componentSqlType = SqlType.valueOf(array.getBaseType());
// Avatica Server will always return non-primitives to ensure nullable is guaranteed.
ColumnMetaData.Rep rep = ColumnMetaData.Rep.serialRepOf(componentSqlType);
AvaticaType componentType = ColumnMetaData.scalar(array.getBaseType(),
array.getBaseTypeName(), rep);
// Update the ArrayType from the Signature
arrayType.updateComponentType(componentType);
// We only need to update the array's type once.
arrayOffsets.remove(j);
}
}
}
rows.add(columns);
}
return new Meta.Frame(offset, done, rows);
}
示例11: getValue
import java.sql.ResultSet; //导入方法依赖的package包/类
private static Object getValue(ResultSet resultSet, int type, int j,
Calendar calendar) throws SQLException {
switch (type) {
case Types.BIGINT:
final long aLong = resultSet.getLong(j + 1);
return aLong == 0 && resultSet.wasNull() ? null : aLong;
case Types.INTEGER:
final int anInt = resultSet.getInt(j + 1);
return anInt == 0 && resultSet.wasNull() ? null : anInt;
case Types.SMALLINT:
final short aShort = resultSet.getShort(j + 1);
return aShort == 0 && resultSet.wasNull() ? null : aShort;
case Types.TINYINT:
final byte aByte = resultSet.getByte(j + 1);
return aByte == 0 && resultSet.wasNull() ? null : aByte;
case Types.DOUBLE:
case Types.FLOAT:
final double aDouble = resultSet.getDouble(j + 1);
return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
case Types.REAL:
final float aFloat = resultSet.getFloat(j + 1);
return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
case Types.DATE:
final Date aDate = resultSet.getDate(j + 1, calendar);
return aDate == null
? null
: (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
case Types.TIME:
final Time aTime = resultSet.getTime(j + 1, calendar);
return aTime == null
? null
: (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
case Types.TIMESTAMP:
final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
return aTimestamp == null ? null : aTimestamp.getTime();
case Types.ARRAY:
final Array array = resultSet.getArray(j + 1);
if (null == array) {
return null;
}
try {
// Recursively extracts an Array using its ResultSet-representation
return extractUsingResultSet(array, calendar);
} catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
// Not every database might implement Array.getResultSet(). This call
// assumes a non-nested array (depends on the db if that's a valid assumption)
return extractUsingArray(array, calendar);
}
case Types.STRUCT:
Struct struct = resultSet.getObject(j + 1, Struct.class);
Object[] attrs = struct.getAttributes();
List<Object> list = new ArrayList<>(attrs.length);
for (Object o : attrs) {
list.add(o);
}
return list;
default:
return resultSet.getObject(j + 1);
}
}
示例12: jdbcGet
import java.sql.ResultSet; //导入方法依赖的package包/类
/** Returns the value of a column of this type from a result set. */
public Object jdbcGet(ResultSet resultSet, int i) throws SQLException {
switch (this) {
case PRIMITIVE_BOOLEAN:
return resultSet.getBoolean(i);
case PRIMITIVE_BYTE:
return resultSet.getByte(i);
case PRIMITIVE_SHORT:
return resultSet.getShort(i);
case PRIMITIVE_INT:
return resultSet.getInt(i);
case PRIMITIVE_LONG:
return resultSet.getLong(i);
case PRIMITIVE_FLOAT:
return resultSet.getFloat(i);
case PRIMITIVE_DOUBLE:
return resultSet.getDouble(i);
case BOOLEAN:
final boolean aBoolean = resultSet.getBoolean(i);
return resultSet.wasNull() ? null : aBoolean;
case BYTE:
final byte aByte = resultSet.getByte(i);
return resultSet.wasNull() ? null : aByte;
case SHORT:
final short aShort = resultSet.getShort(i);
return resultSet.wasNull() ? null : aShort;
case INTEGER:
final int anInt = resultSet.getInt(i);
return resultSet.wasNull() ? null : anInt;
case LONG:
final long aLong = resultSet.getLong(i);
return resultSet.wasNull() ? null : aLong;
case FLOAT:
final float aFloat = resultSet.getFloat(i);
return resultSet.wasNull() ? null : aFloat;
case DOUBLE:
final double aDouble = resultSet.getDouble(i);
return resultSet.wasNull() ? null : aDouble;
case JAVA_SQL_DATE:
return resultSet.getDate(i);
case JAVA_SQL_TIME:
return resultSet.getTime(i);
case JAVA_SQL_TIMESTAMP:
return resultSet.getTimestamp(i);
case ARRAY:
return resultSet.getArray(i);
case STRUCT:
return resultSet.getObject(i, Struct.class);
default:
return resultSet.getObject(i);
}
}