0

I have the following parameterized query and set of arguments:

private String queryBuilder(DetailsRequest apiRequest, Map<String, String> headers) {

    StringBuilder builder = new StringBuilder();
    final String QUERY = "select * from gfc.LSI_ELGBLTY where INSURANCE_ID = ? and SYS_CD = ? and ACCT_TYPE in (?)";

    Object[] params = new Object[]  {
            request.getInsuranceId(),request.getSystemId(),AcctNameBuilder};
}

How can I set these parameters to the above query and print it? I just don't want to execute them. I am using spring-boot and I don't want to create new connection object for this.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Chiche
  • 11
  • 5

1 Answers1

0

Here is one way to do it:

private void printPopulatedQuery(String query, Object[] params) {
    for(Object param : params) {              
          query = query.replaceFirst("\\?", "'" + String.valueOf(param) + "'");
    }

    System.out.println(query);
}

If you don't want numerical parameters to have quotes around them, you can first check the type of the parameter.

mdewit
  • 2,016
  • 13
  • 31