本文整理匯總了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);
}