Setting SQL statement parameter value: column index 1, parameter value [name], value class [java.lang.String], SQL type unknown

北战南征 提交于 2019-12-11 16:07:39

问题


I am passing parameters to Query using NamedParameterJdbcTemplate . But am getting trace details as a warning and parameter binding is not showing.Main problem for is it is showing the executing sql but I want parameter also part of it but only ?(question mark) comes.After the warning binding happens and execution is good but binding is not visible in log.Please help me to check this.

column index 1, parameter value [mike], value class [java.lang.String], SQL type unknown column index 2, parameter value [1], value class [java.lang.Integer], SQL type unknown

Repository:

@Repository
public class DataRepository {
    private static Logger log = LoggerFactory.getLogger(DataRepository.class);

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    public Data findDataObjet() throws Exception {

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("id1", "mike");
        parameters.put("id2", new Long(1));

        String sqlString = "select * from table1 where id1 = ":id1" and id2 = :id2";

        Data extObj = jdbcTemplate.query(sqlString, parameters, (rs) -> {
            if (rs != null && rs.next()) {
                Data innerObj = new Data();
                innerObj.setName(rs.getString("name"));             
                return innerObj;
            } else {
                log.info("No records found:"+rs);
                return null;
            }
        });

        return extObj;

    }
}

application.properties:

spring.datasource.url=url
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver

spring.datasource.type = com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=2

logback-spring.xml:

<springProfile name="dev">
        <logger name="org.springframework.jdbc.core.JdbcTemplate">
            <level value="trace" />
        </logger>
        <logger name="org.springframework.jdbc.core.StatementCreatorUtils">
            <level value="trace" />
        </logger>
        <appender name="dailyRollingFileAppender"
            class="ch.qos.logback.core.rolling.RollingFileAppender">
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <FileNamePattern>${logsPath}TSYS2DM%d{MMddyyyy}.log
                </FileNamePattern>
                <maxHistory>4</maxHistory>
            </rollingPolicy>

            <encoder>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level
                    %logger{35}-%msg %n</Pattern>
            </encoder>

        </appender>
        <root level="INFO">
            <appender-ref ref="dailyRollingFileAppender" />
        </root>
    </springProfile>

Log Trace:

2018-03-07 12:19:42.888 DEBUG 30224 --- [resources/input] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2018-03-07 12:19:42.889 DEBUG 30224 --- [resources/input] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [ select * from table1 where id1 = "?" and id2 = ?;]
2018-03-07 12:19:43.132 TRACE 30224 --- [resources/input] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [mike], value class [java.lang.String], SQL type unknown
2018-03-07 12:19:43.132 TRACE 30224 --- [resources/input] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 2, parameter value [1], value class [java.lang.Integer], SQL type unknown
2018-03-07 12:19:43.439  INFO 30224 --- [resources/input] c.t.f.c.t.t.db.TRMAccountDataRepository  : found record with cnsmr_id:1234

来源:https://stackoverflow.com/questions/49146167/setting-sql-statement-parameter-value-column-index-1-parameter-value-name-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!