本文整理汇总了Java中java.sql.Connection.createArrayOf方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.createArrayOf方法的具体用法?Java Connection.createArrayOf怎么用?Java Connection.createArrayOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Connection
的用法示例。
在下文中一共展示了Connection.createArrayOf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toSqlArray
import java.sql.Connection; //导入方法依赖的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 );
}
示例2: setNonNullParameter
import java.sql.Connection; //导入方法依赖的package包/类
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Object[] parameter,
JdbcType jdbcType) throws SQLException {
String typeName = null;
if (parameter instanceof Integer[]) {
typeName = TYPE_NAME_INTEGER;
} else if (parameter instanceof String[]) {
typeName = TYPE_NAME_VARCHAR;
} else if (parameter instanceof Boolean[]) {
typeName = TYPE_NAME_BOOLEAN;
} else if (parameter instanceof Double[]) {
typeName = TYPE_NAME_NUMERIC;
}
if (typeName == null) {
throw new TypeException("ArrayTypeHandler parameter typeName error, your type is " + parameter.getClass().getName());
}
// 这3行是关键的代码,创建Array,然后ps.setArray(i, array)就可以了
Connection conn = ps.getConnection();
Array array = conn.createArrayOf(typeName, parameter);
ps.setArray(i, array);
}
示例3: nullSafeSet
import java.sql.Connection; //导入方法依赖的package包/类
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
Connection connection = st.getConnection();
if (value == null) {
st.setNull(index, sqlTypes()[0]);
} else {
@SuppressWarnings("unchecked") ArrayList<Long> castObject = (ArrayList) value;
Long[] longs = castObject.toArray(new Long[castObject.size()]);
Array array = connection.createArrayOf("bigint", longs);
st.setArray(index, array);
}
}
示例4: convertToArray
import java.sql.Connection; //导入方法依赖的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;
}
}
示例5: SchemasContainer
import java.sql.Connection; //导入方法依赖的package包/类
public SchemasContainer(Map<Long, PgSchema> schemas, Connection connection) throws SQLException {
this.map = schemas;
final int size = schemas.size();
int i = 0;
Long[] oids = new Long[size];
String[] names = new String[size];
for (Entry<Long, PgSchema> entry : schemas.entrySet()) {
oids[i] = entry.getKey();
names[i] = entry.getValue().getName();
++i;
}
this.oids = connection.createArrayOf("bigint", oids);
this.names = connection.createArrayOf("text", names);
}
示例6: createArrayOf
import java.sql.Connection; //导入方法依赖的package包/类
/**
* {@link java.sql.Connection#createArrayOf(String, Object[])}のラッパー
*
* @param conn コネクション
* @param typeName 配列の要素がマッピングされる型のSQL名。typeNameはデータベース固有の名前で、組込み型、ユーザー定義型、またはこのデータベースでサポートされる標準SQL型の名前のこと。これは、Array.getBaseTypeNameで返される値
* @param elements 返されるオブジェクトを生成する要素
* @return 指定されたSQL型に要素がマッピングされるArrayオブジェクト
*
* @see java.sql.Connection#createArrayOf(String, Object[])
*/
public static Array createArrayOf(final Connection conn, final String typeName, final Object[] elements) {
try {
return conn.createArrayOf(typeName, elements);
} catch (SQLException e) {
throw new UroborosqlRuntimeException(e);
}
}