本文整理汇总了Java中java.sql.PreparedStatement.setArray方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.setArray方法的具体用法?Java PreparedStatement.setArray怎么用?Java PreparedStatement.setArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.setArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testArrayA
import java.sql.PreparedStatement; //导入方法依赖的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");
}
}
示例2: nullSafeSet
import java.sql.PreparedStatement; //导入方法依赖的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);
}
}
示例3: setNonNullParameter
import java.sql.PreparedStatement; //导入方法依赖的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);
}
示例4: setParameterObject
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* PreparedStatementへのパラメータセット処理
*
* @param preparedStatement PreparedStatement
* @param parameterIndex index
* @param param オリジナルパラメータ
* @param parameterMapperManager パラメータ変換管理クラス
* @throws SQLException SQL例外
*/
private void setParameterObject(final PreparedStatement preparedStatement, final int parameterIndex,
final Object param, final BindParameterMapperManager parameterMapperManager) throws SQLException {
//JDBCの受け付ける型に変換
Object jdbcParam = parameterMapperManager.toJdbc(param, preparedStatement.getConnection());
if (Objects.equals(sqlType, SQL_TYPE_NOT_SET)) {
if (jdbcParam instanceof java.sql.Array) {
preparedStatement.setArray(parameterIndex, (java.sql.Array) jdbcParam);
} else {
preparedStatement.setObject(parameterIndex, jdbcParam);
}
} else {
int targetSqlType = sqlType.getVendorTypeNumber();//各JDBCの対応状況が怪しいのでintで扱う
if (jdbcParam != null) {
if (jdbcParam instanceof java.sql.Array) {
preparedStatement.setArray(parameterIndex, (java.sql.Array) jdbcParam);
} else {
preparedStatement.setObject(parameterIndex, jdbcParam, targetSqlType);
}
} else {
preparedStatement.setNull(parameterIndex, targetSqlType);
}
}
}
示例5: nullSafeSet
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SharedSessionContractImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, SQL_TYPES[0]);
} else {
final Array array = session.connection().createArrayOf("text", (String[])value);
st.setArray(index, array);
}
}
示例6: setNonNullParameter
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
ps.setArray(i, (Array) parameter);
}