List of usage examples for java.sql CallableStatement setArray
void setArray(int parameterIndex, Array x) throws SQLException;
java.sql.Array
object. From source file:de.whs.poodle.repositories.TagRepository.java
public void mergeTags(List<Integer> tagIds, int mergeTo) { jdbc.update(con -> {/*from www.j ava2 s . c o m*/ CallableStatement cs = con.prepareCall("{ CALL merge_tags(?,?) }"); Array tagIdsArray = con.createArrayOf("int4", tagIds.toArray()); cs.setArray(1, tagIdsArray); cs.setInt(2, mergeTo); return cs; }); }
From source file:de.awtools.grooocle.varray.VarrayTest.java
@Test public void testOraclesVarray() throws Exception { CallableStatement cs = null; try {/*from ww w .j av a 2s . c o m*/ String arrayElements[] = { "Test3", "Test4", "Test5" }; ArrayDescriptor desc = ArrayDescriptor.createDescriptor("T_STRING_VARRAY", conn); ARRAY newArray = new ARRAY(desc, conn, arrayElements); String spCall = "{ call call_me(?, ?) }"; cs = conn.prepareCall(spCall); cs.setArray(1, newArray); cs.registerOutParameter(2, java.sql.Types.INTEGER); cs.execute(); assertEquals(3, cs.getInt(2)); } finally { if (cs != null) { cs.close(); } } }
From source file:de.whs.poodle.repositories.CourseRepository.java
public void edit(Course course) { try {//from w ww. j a va 2 s. c o m jdbc.update(con -> { CallableStatement cs = con.prepareCall("{ CALL update_course(?,?,?,?,?,?) }"); cs.setInt(1, course.getId()); cs.setString(2, course.getName()); cs.setBoolean(3, course.getVisible()); if (course.getPassword().trim().isEmpty()) cs.setNull(4, Types.VARCHAR); else cs.setString(4, course.getPassword()); Array otherInstructors = con.createArrayOf("int4", course.getOtherInstructorsIds().toArray()); cs.setArray(5, otherInstructors); Array linkedCourses = con.createArrayOf("int4", course.getLinkedCoursesIds().toArray()); cs.setArray(6, linkedCourses); return cs; }); } catch (DuplicateKeyException e) { throw new BadRequestException(); } }
From source file:de.awtools.grooocle.varray.VarrayTest.java
@Test @Ignore/*w w w .j a v a 2 s . c o m*/ public void testOraclesVarrayWithPackage() throws Exception { CallableStatement cs = null; try { String arrayElements[] = { "Test3", "Test4", "Test5" }; // int n = OracleTypeCOLLECTION.TYPE_PLSQL_INDEX_TABLE; // ArrayDescriptor desc = ArrayDescriptor.createDescriptor(); ArrayDescriptor desc = ArrayDescriptor.createDescriptor("CP_TEST.t_ROWNUMBER", conn); ARRAY newArray = new ARRAY(desc, conn, arrayElements); String spCall = "{ call CP_TEST.call_me(?, ?) }"; cs = conn.prepareCall(spCall); cs.setArray(1, newArray); cs.registerOutParameter(2, java.sql.Types.INTEGER); cs.execute(); assertEquals(3, cs.getInt(2)); } finally { if (cs != null) { cs.close(); } } }