public void setString(int parameterIndex, String x) throws SQLException { cstmt.setString(parameterIndex, x); }
public void setString(String parameterName, String x) throws SQLException { cstmt.setString(parameterName, x); }
@Override public void setString(String parameterName, String x) throws SQLException { try { stmt.setString(parameterName, x); } catch (Throwable t) { throw checkException(t); } }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { st.setString( name, javaTypeDescriptor.unwrap( value, String.class, options ) ); } };
public static void executeNoReturnValue(String url, String serviceName, String json) { try (Connection conn = DriverManager.getConnection(url); CallableStatement stmt = conn.prepareCall(sqlNoReturnValue)) { stmt.setString(1, serviceName); stmt.setString(2, json); stmt.execute(); } catch (SQLException e) { throw new RuntimeException("Failed to execute service: " + serviceName, e); } }
@Override public void setString(String parameterName, String x) throws SQLException { SQLException e = null; try { delegate.setString(parameterName, x); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterCallableStatementSet(statementInformation, parameterName, x, e); } }
public static String executeWithReturnValue(String url, String serviceName, String json) { try (Connection conn = DriverManager.getConnection(url); CallableStatement stmt = conn.prepareCall(sqlWithReturnValue)) { stmt.setString(2, serviceName); stmt.setString(3, json); stmt.registerOutParameter(1, java.sql.Types.VARCHAR); if (stmt.execute()) { return stmt.getString(1); } } catch (SQLException e) { throw new RuntimeException("Failed to execute service: " + serviceName, e); } return null; }
@Override public void callableStatement_setString(CallableStatementProxy statement, String parameterName, String x) throws SQLException { if (this.pos < filterSize) { nextFilter().callableStatement_setString(this, statement, parameterName, x); return; } statement.getRawObject().setString(parameterName, x); }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { final String valueStr = javaTypeDescriptor.unwrap( value, String.class, options ); if ( valueStr == null || valueStr.trim().isEmpty() ) { st.setNull( name, getSqlType() ); } else { st.setString( name, valueStr ); } } };
@Test public void testParameterMapper() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(2)).willReturn("OK"); given(connection.prepareCall("{call " + ParameterMapperStoredProcedure.SQL + "(?, ?)}") ).willReturn(callableStatement); ParameterMapperStoredProcedure pmsp = new ParameterMapperStoredProcedure(dataSource); Map<String, Object> out = pmsp.executeTest(); assertEquals("OK", out.get("out")); verify(callableStatement).setString(eq(1), startsWith("Mock for Connection")); verify(callableStatement).registerOutParameter(2, Types.VARCHAR); }
@Override public void setString(String parameterName, String x) throws SQLException { SQLException e = null; try { delegate.setString(parameterName, x); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterCallableStatementSet(statementInformation, parameterName, x, e); } }
@Override public void setString(String parameterName, String x) throws SQLException { try { stmt.setString(parameterName, x); } catch (Throwable t) { throw checkException(t); } }
public static void executeRegister( String schemaName, String tableName, String columnName, String srsName, Connection con) throws SQLException { 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.registerOutParameter(5, Types.INTEGER); ps.registerOutParameter(6, Types.CHAR); ps.executeUpdate(); // DB2TestSetup.LOGGER.log(Level.INFO,ps.getInt(5) + "|" + ps.getString(6)); }
public static void executeUnRegister( String schemaName, String tableName, String columnName, Connection con) throws SQLException { String stmt = "call db2gse.ST_unregister_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.registerOutParameter(4, Types.INTEGER); ps.registerOutParameter(5, Types.CHAR); ps.executeUpdate(); // DB2TestSetup.LOGGER.log(Level.INFO,ps.getInt(4) + "|" + ps.getString(5)); }
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); } }
@Override public void callableStatement_setString(CallableStatementProxy statement, String parameterName, String x) throws SQLException { if (this.pos < filterSize) { nextFilter().callableStatement_setString(this, statement, parameterName, x); return; } statement.getRawObject().setString(parameterName, x); }
@Test public void testCallableStatementOnAfterCallableStatementSetString() throws SQLException { wrappedCallableStatement.setString(null, "foo"); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.<String>isNull(), eq("foo"), ArgumentMatchers.<SQLException>isNull()); }
@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'")); }