當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。