1
我正在使用simpleJDBCTemplate向postgre數據庫插入一個值。現在simpleJDBCTemplate不能取代引用的參數
String sql "insert into testTable values(:bla, :blah, functionThatTakesAText(':blu'))"
BeanPropertySqlParameterSource namedParameters = new BeanPropertySqlParameterSource(lighting);
simpleJdbcTemplate.update(sql, namedParameters);
,藍光參數實際上是一個數字(實際的SQL需要2真正的)是從客戶端提供的文件中讀取。
結果數據庫收到類似以下內容:
insert into testTable values(?, ?, functionThatTakesAText(':blu'))
,並不能取代:藍光參數預期。
我正在使用的當前解決方法是使用正則表達式替換藍色參數的值,但我不確定這是多麼安全。
你會如何解決這個問題?
「請參閱NamedParameterUtils的skipCommentsAndQuotes()方法」我無法在文檔中找到它* * - http://static.springsource.org/spring/docs/2.5.x/api/org/springframework /jdbc/core/namedparam/NamedParameterUtils.html – 2010-07-19 14:29:15
@awregan:它不在文檔中,它在源代碼中。 – skaffman 2010-07-19 14:30:48