<legend id='4eBzV'><style id='4eBzV'><dir id='4eBzV'><q id='4eBzV'></q></dir></style></legend>
    1. <i id='4eBzV'><tr id='4eBzV'><dt id='4eBzV'><q id='4eBzV'><span id='4eBzV'><b id='4eBzV'><form id='4eBzV'><ins id='4eBzV'></ins><ul id='4eBzV'></ul><sub id='4eBzV'></sub></form><legend id='4eBzV'></legend><bdo id='4eBzV'><pre id='4eBzV'><center id='4eBzV'></center></pre></bdo></b><th id='4eBzV'></th></span></q></dt></tr></i><div id='4eBzV'><tfoot id='4eBzV'></tfoot><dl id='4eBzV'><fieldset id='4eBzV'></fieldset></dl></div>

        <bdo id='4eBzV'></bdo><ul id='4eBzV'></ul>
    2. <tfoot id='4eBzV'></tfoot>
      1. <small id='4eBzV'></small><noframes id='4eBzV'>

        java - MySql 中的多个更新语句

        java - Multipile update statements in MySql(java - MySql 中的多个更新语句)

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

            <tbody id='rtjce'></tbody>

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

                <bdo id='rtjce'></bdo><ul id='rtjce'></ul>
                  <legend id='rtjce'><style id='rtjce'><dir id='rtjce'><q id='rtjce'></q></dir></style></legend>
                • 本文介绍了java - MySql 中的多个更新语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我有一个软件,它基本上从我的 MySQL 数据库下载 1.5K 游戏服务器地址.然后它会ping所有这些,然后将在线玩家等信息上传回数据库.流程如下:

                  so I have a software which basically downloads 1.5K game server address from my MySQL db. It then pings all of them and then upload the information such as online players back to the database. The process looks like this:

                  1. 下载服务器地址
                  2. Ping 服务器并获取信息
                  3. 将信息上传回数据库

                  到目前为止,我已经能够解决下载服务器主机名并 ping 它们的部分,但更新服务器时会出现问题.

                  So far I have been able to solve the part where it download the server host name and pings them but the problem arises when updating the servers.

                  为了更新,我考虑过使用 for 循环来构造一个包含许多更新语句的 BIG 字符串并立即执行它,但这很容易发生 sql 注入.因此,理想情况下,人们会想要使用准备好的语句.

                  To update I thought about using a for loop to construct one BIG string of many update statements and execute it at once but this is prone to sql injections. So idealy one would want to use prepared statements.

                  我使用的 SQL 更新语句是:

                  The SQL update statement i'm using is:

                  UPDATE serverlist SET `onlineplayers` = '3', maxplayers = '10', 
                  name = 'A game server' WHERE `ip` = 'xxx.xxx.xxx.xxx' AND `port` = 1234;
                  

                  所以我的问题是:
                  如何使用参数化查询执行所有 1.5K 更新语句?

                  推荐答案

                  如果你用谷歌搜索jdbc 批量更新",你会得到很多结果 喜欢这个 或 这个.

                  If you google for "jdbc bulk update" you'll get lots of results like this one or this one.

                  后者有一个这样的例子:

                  The latter has an example like this:

                  try {
                  ...
                    connection con.setAutoCommit(false);                   
                    PreparedStatement prepStmt = con.prepareStatement(    
                      "UPDATE DEPT SET MGRNO=? WHERE DEPTNO=?");           
                    prepStmt.setString(1,mgrnum1);                         
                    prepStmt.setString(2,deptnum1);
                    prepStmt.addBatch();                                   
                  
                    prepStmt.setString(1,mgrnum2);                        
                    prepStmt.setString(2,deptnum2);
                    prepStmt.addBatch();
                    int [] numUpdates=prepStmt.executeBatch();             
                    for (int i=0; i < numUpdates.length; i++) {            
                      if (numUpdates[i] == -2)
                        System.out.println("Execution " + i + 
                          ": unknown number of rows updated");
                      else
                        System.out.println("Execution " + i + 
                          "successful: " numUpdates[i] + " rows updated");
                    }
                    con.commit();                                          
                  } catch(BatchUpdateException b) {
                    // process BatchUpdateException
                  } 
                  

                  这篇关于java - MySql 中的多个更新语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Slf4j LoggerFactory.getLogger and sonarqube(Slf4j LoggerFactory.getLogger 和 sonarqube)
                  Security - Array is stored directly(安全性 - 数组直接存储)
                  SonarQube quot;Class Not Foundquot; during Main AST Scan(SonarQube“找不到类在主 AST 扫描期间)
                  Integrate Spock#39;s test with Sonar(将 Spock 的测试与声纳集成)
                  How do I make Hudson/Jenkins fail if Sonar thresholds are breached?(如果违反声纳阈值,我如何让 Hudson/Jenkins 失败?)
                  automatically add curly brackets to all if/else/for/while etc. in a java code-base(自动将大括号添加到 java 代码库中的所有 if/else/for/while 等)
                  <i id='0LjK0'><tr id='0LjK0'><dt id='0LjK0'><q id='0LjK0'><span id='0LjK0'><b id='0LjK0'><form id='0LjK0'><ins id='0LjK0'></ins><ul id='0LjK0'></ul><sub id='0LjK0'></sub></form><legend id='0LjK0'></legend><bdo id='0LjK0'><pre id='0LjK0'><center id='0LjK0'></center></pre></bdo></b><th id='0LjK0'></th></span></q></dt></tr></i><div id='0LjK0'><tfoot id='0LjK0'></tfoot><dl id='0LjK0'><fieldset id='0LjK0'></fieldset></dl></div>

                  <small id='0LjK0'></small><noframes id='0LjK0'>

                  <tfoot id='0LjK0'></tfoot>

                  • <bdo id='0LjK0'></bdo><ul id='0LjK0'></ul>
                        1. <legend id='0LjK0'><style id='0LjK0'><dir id='0LjK0'><q id='0LjK0'></q></dir></style></legend>

                              <tbody id='0LjK0'></tbody>