私は Spring JdbcTemplate を使用していますが、実際には int の配列である列を更新するクエリがある時点で立ち往生しています。データベースは postgres 8.3.7 です。これは私が使用しているコードです:
public int setUsersArray(int idUser, int idDevice, Collection<Integer> ids) {
int update = -666;
int[] tipi = new int[3];
tipi[0] = java.sql.Types.INTEGER;
tipi[1] = java.sql.Types.INTEGER;
tipi[2] = java.sql.Types.ARRAY;
try {
update = this.jdbcTemplate.update(setUsersArrayQuery, new Object[] {
ids, idUser, idDevice }, tipi);
} catch (Exception e) {
e.printStackTrace();
}
return update;
}
クエリは「update table_name set array_column = ? where id_user = ? and id_device = ?」です。私はこの例外を受け取ります:
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [更新 acotel_msp.users_mau set denied_sub_client = ? id_users = ? id_mau = ?]; 列インデックスが範囲外です: 4、列数: 3.; ネストされた例外は org.postgresql.util.PSQLException: The column index is out of range: 4, number of columns: 3.
原因: org.postgresql.util.PSQLException: 列インデックスが範囲外です: 4、列数: 3。
春のjdbcテンプレートドキュメントを調べましたが、助けが見つかりません。探し続けます。とにかく誰かが私を正しい方向に向けることができますか? ありがとう!
編集 :
明らかに順序が間違っていました、私のせいです...
私はあなたの両方のソリューションを試しましたが、最初のケースではこれがありました:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; 不適切な SQL 文法 [update users set denied_sub_client = ? id_users = ? id_device = ?]; ネストされた例外は org.postgresql.util.PSQLException です: java.util.ArrayList のインスタンスを Types.ARRAY 型にキャストできません
私がこれを持っていた2番目の解決策を試してみてください:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; 不適切な SQL 文法 [update users set denied_sub_client = ? id_users = ? id_device = ?]; ネストされた例外は org.postgresql.util.PSQLException: Cannot cast an instance of [Ljava.lang.Object; です。タイプTypes.ARRAYに
java.sql.Array のインスタンスが必要だと思いますが、JdbcTemplate を使用して作成するにはどうすればよいですか?