当前位置: 首页>>代码示例>>Java>>正文


Java Array类代码示例

本文整理汇总了Java中java.sql.Array的典型用法代码示例。如果您正苦于以下问题:Java Array类的具体用法?Java Array怎么用?Java Array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Array类属于java.sql包,在下文中一共展示了Array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testArrayA

import java.sql.Array; //导入依赖的package包/类
public void testArrayA() {

        try {
            String ddl0 = "DROP TABLE ARRAYTEST IF EXISTS";
            String ddl1 = "CREATE TABLE ARRAYTEST(A INTEGER ARRAY)";
            String dml1 = "INSERT INTO ARRAYTEST VALUES(ARRAY[0,0])";
            String dml2 = "INSERT INTO ARRAYTEST VALUES ?";

            statement.execute(ddl0);
            statement.execute(ddl1);
            statement.execute(dml1);

            PreparedStatement ps      = connection.prepareStatement(dml2);
            Object[]          objects = new Object[] {
                "1", 3, 9
            };
            Array array = connection.createArrayOf("INTEGER", objects);

            ps.setArray(1, array);
            ps.execute();
        } catch (SQLException e) {
            e.printStackTrace();
            fail("array failure");
        }
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:26,代码来源:TestTypeConversion.java

示例2: toSqlArray

import java.sql.Array; //导入依赖的package包/类
public Array toSqlArray ( final Connection connection, final Event event ) throws SQLException
{
    final DateFormat isoDateFormat = new SimpleDateFormat ( isoDatePatterrn );
    final String[] fields;
    // array must be large enough to hold all attributes plus id and both time stamps
    fields = new String[ ( event.getAttributes ().size () + 3 ) * 2];
    // now populate values
    fields[0] = "id";
    fields[1] = event.getId ().toString ();
    fields[2] = "sourceTimestamp";
    fields[3] = isoDateFormat.format ( event.getSourceTimestamp () );
    fields[4] = "entryTimestamp";
    fields[5] = isoDateFormat.format ( event.getEntryTimestamp () );
    int i = 6;
    for ( final Entry<String, Variant> entry : event.getAttributes ().entrySet () )
    {
        fields[i] = entry.getKey ();
        fields[i + 1] = entry.getValue ().toString ();
        i += 2;
    }
    return connection.createArrayOf ( "text", fields );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:EventConverter.java

示例3: shortArraysWithNull

import java.sql.Array; //导入依赖的package包/类
@Test public void shortArraysWithNull() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.SMALLINT, "SMALLINT", Rep.SHORT);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<Short> elements = new ArrayList<>();
      for (int j = 0; j < 4; j++) {
        short value = (short) r.nextInt(Short.MAX_VALUE);
        // 50% of the time, negate the value
        if (0 == r.nextInt(2)) {
          value *= -1;
        }
        elements.add(Short.valueOf(value));
      }
      elements.add(null);
      arrays.add(createArray("SMALLINT", component, elements));
    }
    // Verify read/write
    writeAndReadArrays(conn, "short_arrays", "SMALLINT", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:25,代码来源:ArrayTypeTest.java

示例4: put

import java.sql.Array; //导入依赖的package包/类
/**
 * Stores the Array in static for username + connectionId
 * 
 * @param array
 *            the Array to store
 */
public void put(Array array) {

	debug("Creating an array for user: " + connectionKey);
	if (array == null) {
		throw new IllegalArgumentException("array is null!");
	}

	Set<Array> arraySet = arrayMap.get(connectionKey);
	if (arraySet == null) {
		arraySet = new LinkedHashSet<Array>();
	}

	arraySet.add(array);
	arrayMap.put(connectionKey, arraySet);

}
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:23,代码来源:ConnectionStore.java

示例5: test

import java.sql.Array; //导入依赖的package包/类
@Test
public void test() {
	BindParameterMapperManager parameterMapperManager = new BindParameterMapperManager();
	Array jdbcArray = newProxy(Array.class);
	Double[] array = { Double.valueOf(111.11d), Double.valueOf(222.22d) };

	Connection conn = newProxy(Connection.class, (proxy, method, args) -> {
		if (method.getName().equals("createArrayOf")) {
			assertThat(args[0], is("FLOAT"));
			assertThat(args[1], is(array));
			return jdbcArray;
		}
		return method.invoke(proxy, args);
	});

	assertThat(parameterMapperManager.toJdbc(array, conn), is(jdbcArray));

	Object[] objArray = { Double.valueOf(333.33d), "A" };
	assertThat(parameterMapperManager.toJdbc(objArray, conn), is(objArray));

}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:22,代码来源:DoubleWrapperArrayParameterMapperTest.java

示例6: convertToArray

import java.sql.Array; //导入依赖的package包/类
protected Array convertToArray(Connection con, Set<Access> accessTypes) throws SQLException {
	if (accessTypes != null) {
		Integer[] accessIds = new Integer[accessTypes.size()];
		int j = 0;
		for (Access access : accessTypes) {
			accessIds[j++] = access.getId();
		}
		return con.createArrayOf("smallint", accessIds);
	} else {
		return null;
	}
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:13,代码来源:AbstractWayGraphDaoImpl.java

示例7: createArrayOf

import java.sql.Array; //导入依赖的package包/类
/**
     *  Factory method for creating Array objects.
     * <p>
     *  <b>Note: </b>When <code>createArrayOf</code> is used to create an array object
     *  that maps to a primitive data type, then it is implementation-defined
     *  whether the <code>Array</code> object is an array of that primitive
     *  data type or an array of <code>Object</code>.
     *  <p>
     *  <b>Note: </b>The JDBC driver is responsible for mapping the elements
     *  <code>Object</code> array to the default JDBC SQL type defined in
     *  java.sql.Types for the given class of <code>Object</code>. The default
     *  mapping is specified in Appendix B of the JDBC specification.  If the
     *  resulting JDBC type is not the appropriate type for the given typeName then
     *  it is implementation defined whether an <code>SQLException</code> is
     *  thrown or the driver supports the resulting conversion.
     *
     *  @param typeName the SQL name of the type the elements of the array map to. The typeName is a
     *  database-specific name which may be the name of a built-in type, a user-defined type or a standard  SQL type supported by this database. This
     *   is the value returned by <code>Array.getBaseTypeName</code>
     *  @param elements the elements that populate the returned object
     *  @return an Array object whose elements map to the specified SQL type
     *  @throws SQLException if a database error occurs, the JDBC type is not
     *   appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection
     *  @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this data type
     *  @since 1.6
     */
//#ifdef JAVA6
    public Array createArrayOf(String typeName,
                               Object[] elements) throws SQLException {

        checkClosed();

        if (typeName == null) {
            throw JDBCUtil.nullArgument();
        }
        typeName = typeName.toUpperCase();

        int typeCode = Type.getTypeNr(typeName);

        if (typeCode < 0) {
            throw JDBCUtil.invalidArgument(typeName);
        }

        Type type = Type.getDefaultType(typeCode);

        if (type.isArrayType() || type.isLobType() || type.isRowType()) {
            throw JDBCUtil.invalidArgument(typeName);
        }

        Object[] newData = new Object[elements.length];

        try {
            for (int i = 0; i < elements.length; i++) {
                Object o = type.convertJavaToSQL(sessionProxy, elements[i]);

                newData[i] = type.convertToTypeLimits(sessionProxy, o);
            }
        } catch (HsqlException e) {
            throw JDBCUtil.sqlException(e);
        }

        return new JDBCArray(newData, type, this);
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:64,代码来源:JDBCConnection.java

示例8: createArrayOf

import java.sql.Array; //导入依赖的package包/类
public Array createArrayOf(String typeName, Object[] elements) throws SQLException
{
	try
	{
		return realConnection.createArrayOf(typeName, elements);
	}
	catch(SQLException s)
	{
		String methodCall = "createArrayOf(" + typeName + ", " + elements + ")";
		reportException(methodCall, s, null);
		throw s;
	}
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:14,代码来源:ConnectionSpy.java

示例9: createDataTypesRows

import java.sql.Array; //导入依赖的package包/类
protected void createDataTypesRows(RowSet crs) throws SQLException {

        Integer aInteger = 100;
        String aChar = "Oswald Cobblepot";
        Long aLong = Long.MAX_VALUE;
        Short aShort = Short.MAX_VALUE;
        Double aDouble = Double.MAX_VALUE;
        BigDecimal aBigDecimal = BigDecimal.ONE;
        Boolean aBoolean = false;
        Float aFloat = Float.MAX_VALUE;
        Byte aByte = Byte.MAX_VALUE;
        Date aDate = Date.valueOf(LocalDate.now());
        Time aTime = Time.valueOf(LocalTime.now());
        Timestamp aTimeStamp = Timestamp.valueOf(LocalDateTime.now());
        Array aArray = new StubArray("INTEGER", new Object[1]);
        Ref aRef = new SerialRef(new StubRef("INTEGER", query));
        byte[] bytes = new byte[10];
        crs.moveToInsertRow();
        crs.updateInt(1, aInteger);
        crs.updateString(2, aChar);
        crs.updateString(3, aChar);
        crs.updateLong(4, aLong);
        crs.updateBoolean(5, aBoolean);
        crs.updateShort(6, aShort);
        crs.updateDouble(7, aDouble);
        crs.updateBigDecimal(8, aBigDecimal);
        crs.updateFloat(9, aFloat);
        crs.updateByte(10, aByte);
        crs.updateDate(11, aDate);
        crs.updateTime(12, aTime);
        crs.updateTimestamp(13, aTimeStamp);
        crs.updateBytes(14, bytes);
        crs.updateArray(15, aArray);
        crs.updateRef(16, aRef);
        crs.updateDouble(17, aDouble);
        crs.insertRow();
        crs.moveToCurrentRow();

    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:CommonCachedRowSetTests.java

示例10: getArray

import java.sql.Array; //导入依赖的package包/类
public Array getArray(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getArray(parameterIndex);
        }
        throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:13,代码来源:CallableStatementWrapper.java

示例11: getNullableResult

import java.sql.Array; //导入依赖的package包/类
@Override
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
	Array array = rs.getArray(columnName);
	return array == null ? null : array.getArray();
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:6,代码来源:ArrayTypeHandler.java

示例12: fromSqlArray

import java.sql.Array; //导入依赖的package包/类
public Event fromSqlArray ( final Array array ) throws SQLException, ParseException
{
    final DateFormat isoDateFormat = new SimpleDateFormat ( isoDatePatterrn );
    final EventBuilder eb = Event.create ();
    final String[] fields = (String[])array.getArray ();
    for ( int i = 0; i < fields.length; i += 2 )
    {
        final String key = fields[i];
        final String value = fields[i + 1];

        if ( key.equals ( "id" ) )
        {
            eb.id ( UUID.fromString ( value ) );
        }
        else if ( key.equals ( "sourceTimestamp" ) )
        {
            eb.sourceTimestamp ( isoDateFormat.parse ( value ) );
        }
        else if ( key.equals ( "entryTimestamp" ) )
        {
            eb.entryTimestamp ( isoDateFormat.parse ( value ) );
        }
        else
        {
            eb.attribute ( key, VariantEditor.toVariant ( value ) );
        }
    }
    return eb.build ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:30,代码来源:EventConverter.java

示例13: getArray

import java.sql.Array; //导入依赖的package包/类
@SuppressWarnings("unchecked") @Override public Array getArray() throws SQLException {
  final Object o = getObject();
  if (o == null) {
    return null;
  }
  if (o instanceof ArrayImpl) {
    return (ArrayImpl) o;
  }
  // If it's not an Array already, assume it is a List.
  return new ArrayImpl((List<Object>) o, this);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:12,代码来源:AbstractCursor.java

示例14: test06

import java.sql.Array; //导入依赖的package包/类
@Test(enabled = true)
public void test06() throws Exception {
    Object[] coffees = new Object[]{"Espresso", "Colombian", "French Roast",
        "Cappuccino"};
    Array a = new StubArray("VARCHAR", coffees);
    Object[] values = {a};
    SQLInputImpl sqli = new SQLInputImpl(values, map);
    Array a2 = sqli.readArray();
    assertTrue(Arrays.equals((Object[]) a2.getArray(), (Object[]) a.getArray()));
    assertTrue(a.getBaseTypeName().equals(a2.getBaseTypeName()));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SQLInputImplTests.java

示例15: test04

import java.sql.Array; //导入依赖的package包/类
@Test(enabled = true)
public void test04() throws Exception {
    Object[] coffees = new Object[]{"Espresso", "Colombian", "French Roast",
        "Cappuccino"};
    Array a = new StubArray("VARCHAR", coffees);
    outImpl.writeArray(a);
    SerialArray sa = (SerialArray) results.get(0);
    assertTrue(Arrays.equals(coffees, (Object[]) sa.getArray()));
    assertTrue(a.getBaseTypeName().equals(sa.getBaseTypeName()));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SQLOutputImplTests.java


注:本文中的java.sql.Array类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。