0
  select group_id,group_name,directory_id from csr_dim_group where group_name IN ('RG-Actuary SecShared Best's Week') and directory_id=?

    PreparedStatement statement = getStatement(sql);
    statement.setLong(1, dirId);
    rs = statement.executeQuery(); 

Getting SQLServerException. Can you please help me how to escape single quote in preparedStatement.?

2021-11-10 21:32:02,892 ERROR [com.mcafee.mesa.reportdbin.util.UpdateDirectoryDbUtil] SQL Exception during get directory groups: com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:1115) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setValue(SQLServerPreparedStatement.java:1129) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setLong(SQLServerPreparedStatement.java:1429) at org.apache.commons.dbcp.DelegatingPreparedStatement.setLong(DelegatingPreparedStatement.java:123) at org.apache.commons.dbcp.DelegatingPreparedStatement.setLong(DelegatingPreparedStatement.java:123) at com.mcafee.mesa.reportdbin.util.UpdateDirectoryDbUtil.getDirectoryGroups(UpdateDirectoryDbUtil.java:197) at com.mcafee.mesa.server.project.services.directory.UpdateDirectoryHelper.updateDirectoryGroup(UpdateDirectoryHelper.java:584)

madhusudhan
  • 370
  • 1
  • 4
  • 18

1 Answers1

-2

You would use \' in the string to escape the '. The \ is used to escape reserved characters. You can also do \" to escape quotes.

GouramEats
  • 51
  • 8