久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='lsUmd'><tr id='lsUmd'><dt id='lsUmd'><q id='lsUmd'><span id='lsUmd'><b id='lsUmd'><form id='lsUmd'><ins id='lsUmd'></ins><ul id='lsUmd'></ul><sub id='lsUmd'></sub></form><legend id='lsUmd'></legend><bdo id='lsUmd'><pre id='lsUmd'><center id='lsUmd'></center></pre></bdo></b><th id='lsUmd'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lsUmd'><tfoot id='lsUmd'></tfoot><dl id='lsUmd'><fieldset id='lsUmd'></fieldset></dl></div>

      <small id='lsUmd'></small><noframes id='lsUmd'>

      • <bdo id='lsUmd'></bdo><ul id='lsUmd'></ul>

      <legend id='lsUmd'><style id='lsUmd'><dir id='lsUmd'><q id='lsUmd'></q></dir></style></legend>
      <tfoot id='lsUmd'></tfoot>

        JdbcTemplate 不支持參數化查詢“IN"的情況?必須

        JdbcTemplate does not support Parameterized Query #39;IN#39; case? Must by NamedParameterJdbcTemplate?(JdbcTemplate 不支持參數化查詢“IN的情況?必須按 NamedParameterJdbcTemplate 嗎?)

        • <bdo id='WrPkP'></bdo><ul id='WrPkP'></ul>
            • <i id='WrPkP'><tr id='WrPkP'><dt id='WrPkP'><q id='WrPkP'><span id='WrPkP'><b id='WrPkP'><form id='WrPkP'><ins id='WrPkP'></ins><ul id='WrPkP'></ul><sub id='WrPkP'></sub></form><legend id='WrPkP'></legend><bdo id='WrPkP'><pre id='WrPkP'><center id='WrPkP'></center></pre></bdo></b><th id='WrPkP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WrPkP'><tfoot id='WrPkP'></tfoot><dl id='WrPkP'><fieldset id='WrPkP'></fieldset></dl></div>
                  <tbody id='WrPkP'></tbody>
                <legend id='WrPkP'><style id='WrPkP'><dir id='WrPkP'><q id='WrPkP'></q></dir></style></legend>

                <tfoot id='WrPkP'></tfoot>

                  <small id='WrPkP'></small><noframes id='WrPkP'>

                1. 本文介紹了JdbcTemplate 不支持參數化查詢“IN"的情況?必須按 NamedParameterJdbcTemplate 嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  為了防止 SQL 注入攻擊,我項目中的所有 SQL 語句代碼都應該轉換為參數化查詢.但是當查詢條件包含IN"案例時,我遇到了問題.像這樣(使用 DB2 數據庫):

                  Aimed at preventing SQL injection attacks, all the SQL Statement code in my project should transformed to Parameterized Query. But I got a problem when the query condition includes a 'IN' case. Like this (Using DB2 database):

                  String employeeId = 'D2309';
                  String name = "%brady%";
                  
                  List<Integer> userRights = new ArrayList<Integer>();
                  userRights.add(1);
                  userRights.add(2);
                  userRights.add(3);
                  
                  String sql = "SELECT * FROM T_EMPLOYEE WHERE EMPLOYEE_ID = ? AND NAME LIKE ? 
                  AND RIGHT IN (?)";
                  
                  jdbcTemplate.query(sql, new Object[] {employeeId, name, userRights}, new 
                  EmployeeRowMapper());
                  

                  以上代碼運行失敗,出現異常:

                  The above code runs failed with the exception:

                  org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad 
                  SQL grammar [SELECT * FROM T_EMPLOYEE WHERE EMPLOYEE_ID = ? AND NAME LIKE ? AND 
                  RIGHT IN (?)]; nested exception is com.ibm.db2.jcc.am.io: [jcc][1091][10824]
                  [3.57.82] .... ERRORCODE=-4461, SQLSTATE=42815
                  

                  這里的問題是 JdbcTemplate 不支持 IN case 的參數化查詢嗎?我知道這項工作可以通過NamedParameterJdbcTemplate來完成,是否只有NamedParameterJdbcTemplate可以做IN case查詢?

                  The question here is that does not JdbcTemplate support Parameterized Query for IN case? and I know this work can be done by NamedParameterJdbcTemplate, and whether only NamedParameterJdbcTemplate can do IN case query?

                  非常感謝.

                  推薦答案

                  正如我在評論中已經提到的,我對這個解決方案并不滿意,因為它會動態生成許多 SQL 語句.鑒于 userRights 的數量介于 1 和 n 之間,它需要在緩存中最多 n 個準備好的語句.

                  As I already mentioned in the comments, I'm not happy with this solution as it dynamically generates a number of SQL statements. Given the number of userRights is between 1 and n, it requires up to n prepared statements in the cache.

                  以下應該可以工作(我沒有嘗試過).

                  The below should work (I did not try it).

                  String employeeId = 'D2309';
                  String name = "%brady%";
                  
                  List<Integer> userRights = new ArrayList<Integer>();
                  userRights.add(1);
                  userRights.add(2);
                  userRights.add(3);
                  
                  // build the input string
                  StringBuilder sb = new StringBuilder();
                  for (int i = 0; i < userRights.size; i++) {
                      sb.append("?");
                      if (i < userRights.size() - 1) {
                          sb.append(", ");
                      }
                  }
                  
                  // build the SQL
                  String sql = "SELECT * FROM T_EMPLOYEE WHERE EMPLOYEE_ID = ?" +
                      " AND NAME LIKE ?" +
                      " AND RIGHT IN (" + sb.toString() + ")";
                  
                  // init the object array
                  // size is employeeId + name + right
                  Object[] param = new Object[2 + userRights.size()];
                  
                  // fill it
                  param[0] = employeeId;
                  param[1] = name;
                  
                  for (int i = 0; i < userRights.size(); i++) {
                      param[i + 2] = userRights.get(i);
                  }
                  
                  jdbcTemplate.query(sql, param, new EmployeeRowMapper());
                  

                  這篇關于JdbcTemplate 不支持參數化查詢“IN"的情況?必須按 NamedParameterJdbcTemplate 嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                  <tfoot id='bUbVL'></tfoot>
                      <tbody id='bUbVL'></tbody>
                      • <i id='bUbVL'><tr id='bUbVL'><dt id='bUbVL'><q id='bUbVL'><span id='bUbVL'><b id='bUbVL'><form id='bUbVL'><ins id='bUbVL'></ins><ul id='bUbVL'></ul><sub id='bUbVL'></sub></form><legend id='bUbVL'></legend><bdo id='bUbVL'><pre id='bUbVL'><center id='bUbVL'></center></pre></bdo></b><th id='bUbVL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bUbVL'><tfoot id='bUbVL'></tfoot><dl id='bUbVL'><fieldset id='bUbVL'></fieldset></dl></div>
                        • <bdo id='bUbVL'></bdo><ul id='bUbVL'></ul>

                          <small id='bUbVL'></small><noframes id='bUbVL'>

                          1. <legend id='bUbVL'><style id='bUbVL'><dir id='bUbVL'><q id='bUbVL'></q></dir></style></legend>

                            主站蜘蛛池模板: 亚洲一区 | 久操伊人| a a毛片| 国产第一页在线播放 | a成人| www.av在线| 久久久久国产一区二区 | 看一级毛片视频 | 91嫩草精品 | 91精品国产一二三 | 久久久久国产一区二区三区 | 日韩在线一区二区三区 | 精品粉嫩aⅴ一区二区三区四区 | 日韩成人免费视频 | 日韩国产中文字幕 | 国产精品高潮呻吟久久av黑人 | 亚洲一区二区三区免费在线 | 色男人的天堂 | 欧美国产激情 | 欧美在线视频不卡 | 免费在线视频精品 | 免费黄色的网站 | 久久久九九 | 久久i | 九九热精品在线视频 | 亚欧午夜| 一区二区三区免费在线观看 | 五月综合激情网 | 国产视频h| 欧美日韩精品久久久免费观看 | 日本成人在线免费视频 | 黑人巨大精品欧美一区二区免费 | 永久精品| 国产色婷婷精品综合在线播放 | v片网站 | 在线一区 | 久久九七 | 国产精品美女www | 国产视频一区在线观看 | 亚洲精品久久久久中文字幕欢迎你 | 日韩在线91 |