public void setInt(String parameterName, int x) throws SQLException { cstmt.setInt(parameterName, x); }
public void setInt(int parameterIndex, int x) throws SQLException { cstmt.setInt(parameterIndex, x); }
@Override public void setInt(String parameterName, int x) throws SQLException { try { stmt.setInt(parameterName, x); } catch (Throwable t) { throw checkException(t); } }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { st.setInt( name, javaTypeDescriptor.unwrap( value, Integer.class, options ) ); } };
@Override public void setInt(String parameterName, int x) throws SQLException { SQLException e = null; try { delegate.setInt(parameterName, x); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterCallableStatementSet(statementInformation, parameterName, x, e); } }
@Override public void callableStatement_setInt(CallableStatementProxy statement, String parameterName, int x) throws SQLException { if (this.pos < filterSize) { nextFilter().callableStatement_setInt(this, statement, parameterName, x); return; } statement.getRawObject().setInt(parameterName, x); }
@Test public void testFunctionWithJDBC() { doInJPA( this::entityManagerFactory, entityManager -> { //tag::sql-call-function-mysql-example[] final AtomicReference<Integer> phoneCount = new AtomicReference<>(); Session session = entityManager.unwrap( Session.class ); session.doWork( connection -> { try (CallableStatement function = connection.prepareCall( "{ ? = call fn_count_phones(?) }" )) { function.registerOutParameter( 1, Types.INTEGER ); function.setInt( 2, 1 ); function.execute(); phoneCount.set( function.getInt( 1 ) ); } } ); //end::sql-call-function-mysql-example[] assertEquals(Integer.valueOf(2), phoneCount.get()); }); } }
@Test public void testStoredProcedureReturnValue() { doInJPA( this::entityManagerFactory, entityManager -> { Session session = entityManager.unwrap( Session.class ); session.doWork( connection -> { CallableStatement function = null; try { function = connection.prepareCall("{ ? = call fn_count_phones(?) }"); function.registerOutParameter(1, Types.INTEGER); function.setInt(2, 1); function.execute(); int phoneCount = function.getInt(1); assertEquals(2, phoneCount); } finally { if ( function != null ) { function.close(); } } } ); } ); } }
@Override public void setInt(String parameterName, int x) throws SQLException { SQLException e = null; try { delegate.setInt(parameterName, x); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterCallableStatementSet(statementInformation, parameterName, x, e); } }
@Override public void setInt(String parameterName, int x) throws SQLException { try { stmt.setInt(parameterName, x); } catch (Throwable t) { throw checkException(t); } }
@Override public void callableStatement_setInt(CallableStatementProxy statement, String parameterName, int x) throws SQLException { if (this.pos < filterSize) { nextFilter().callableStatement_setInt(this, statement, parameterName, x); return; } statement.getRawObject().setInt(parameterName, x); }
cs.setDate(index, new java.sql.Date(date.getTime())); }else if(value instanceof Integer){ cs.setInt(index, (Integer)value); }else if(value instanceof Float){ cs.setFloat(index, (Float)value);
@Test public void testCallableStatementOnAfterCallableStatementSetInt() throws SQLException { wrappedCallableStatement.setInt(null, 0); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.<String>isNull(), eq(0), ArgumentMatchers.<SQLException>isNull()); }
public static void executeRegisterAndCalculateExtent( String schemaName, String tableName, String columnName, String srsName, Connection con) throws SQLException { try { String stmt = "call db2gse.ST_register_spatial_column(?,?,?,?,?,?,?)"; String s = "{" + stmt + "}"; CallableStatement ps = con.prepareCall(s); ps.setString(1, quote(schemaName)); ps.setString(2, quote(tableName)); ps.setString(3, quote(columnName)); ps.setString(4, srsName); ps.setInt(5, 1); ps.registerOutParameter(6, Types.INTEGER); ps.registerOutParameter(7, Types.CHAR); ps.executeUpdate(); // DB2TestSetup.LOGGER.log(Level.INFO,ps.getInt(5) + "|" + // ps.getString(6)); } catch (SQLException ex) { // // may happen for spatial extender versions < 10 // fall back registering without extent calculation executeRegisterAndCalculateExtent(schemaName, tableName, columnName, srsName, con); } }
@Test public void binaryExcludedTrue() throws SQLException { // given P6LogOptions.getActiveInstance().setExcludebinary(true); // when String paramValName = "param_val"; String paramIntName = "param_id"; String resultParamName = "result_param"; // execute the statement String query = "{call test_proc_binary(?,?,?)}"; CallableStatement call = connection.prepareCall(query); call.setBytes(paramValName, "foo".getBytes(StandardCharsets.UTF_8)); call.setInt(paramIntName, TEST_IMG_ID); call.registerOutParameter(resultParamName, Types.INTEGER); call.execute(); // out vals not logged anyway https://github.com/p6spy/p6spy/issues/133 // byte[] retVal = call.getBytes(resultParamName); // assertEquals("foo", retVal); call.close(); // then assertTrue( getLastLogEntry().contains("{call test_proc_binary(?,?,?)} " + paramIntName + ":2000, " + paramValName + ":'[binary]'") // || getLastLogEntry().contains("{call test_proc_binary(?,?,?)} " + paramValName + ":'[binary]', " + paramIntName + ":2000")); }
@Test public void binaryExcludedFalse() throws SQLException { // given P6LogOptions.getActiveInstance().setExcludebinary(false); // when String paramValName = "param_val"; String paramIntName = "param_id"; String resultParamName = "result_param"; // execute the statement String query = "{call test_proc_binary(?,?,?)}"; CallableStatement call = connection.prepareCall(query); call.setBytes(paramValName, "foo".getBytes(StandardCharsets.UTF_8)); call.setInt(paramIntName, TEST_IMG_ID); call.registerOutParameter(resultParamName, Types.INTEGER); call.execute(); // out vals not logged anyway https://github.com/p6spy/p6spy/issues/133 // byte[] retVal = call.getBytes(resultParamName); // assertEquals("foo", retVal); call.close(); // then assertTrue( getLastLogEntry().contains("{call test_proc_binary(?,?,?)} " + paramIntName + ":2000, " + paramValName + ":'666F6F'") // || getLastLogEntry().contains("{call test_proc_binary(?,?,?)} " + paramValName + ":'666F6F', " + paramIntName + ":2000")); }
@Test public void testStoredProcedureWithNullInputParameter() throws SQLException { this.clearLogEntries(); // execute the statement String query = "{call test_proc(?,?,?)}"; CallableStatement stmt = connection.prepareCall(query); stmt.registerOutParameter(3, Types.INTEGER); stmt.setInt(1, 1); stmt.setNull(2, Types.VARCHAR); stmt.execute(); int retVal = stmt.getInt(3); assertEquals(2, retVal); stmt.close(); // verify that the third parameter is NULL assertTrue(getLastLogEntry().contains("1,NULL")); }
@Test public void testStoredProcedureNoResultSet() throws SQLException { this.clearLogEntries(); // execute the statement String query = "{call test_proc(?,?,?)}"; CallableStatement call = connection.prepareCall(query); call.registerOutParameter(3, Types.INTEGER); call.setInt(1, 1); call.setString(2, "hi"); call.execute(); int retVal = call.getInt(3); assertEquals(2, retVal); call.close(); // the last log message should have the original query assertTrue(getLastLogEntry().contains(query)); // verify that the bind parameters are resolved in the log message assertTrue(getLastLogEntry().contains("1,'hi'")); }
@Test public void testNamedParameters() throws SQLException { this.clearLogEntries(); String param1Name = "param1"; String param2Name = "param2"; String resultParamName = "result_param"; // execute the statement String query = "{call test_proc(?,?,?)}"; CallableStatement call = connection.prepareCall(query); call.setInt(param1Name, 1); call.setString(param2Name, "hi"); call.registerOutParameter(resultParamName, Types.INTEGER); call.execute(); int retVal = call.getInt(resultParamName); assertEquals(2, retVal); call.close(); // the last log message should have the original query assertTrue(getLastLogEntry().contains(query)); assertTrue(getLastLogEntry().contains("{call test_proc(?,?,?)}")); assertTrue(getLastLogEntry().contains(param1Name+":"+"1")); assertTrue(getLastLogEntry().contains(param2Name+":"+"'hi'")); }