最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java一個數(shù)據(jù)整理的方法代碼實例

 更新時間:2019年09月06日 17:05:16   作者:包飽飽  
這篇文章主要介紹了java一個數(shù)據(jù)整理的方法代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

這篇文章主要介紹了java一個數(shù)據(jù)整理的方法代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

import java.sql.*;

public class Main {
   //本地數(shù)據(jù)庫
  // static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  // static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/aite?useSSL=false&serverTimezone=UTC";
  // static final String USER = "root";
  // static final String PASS = "root";

  //測試服務器數(shù)據(jù)庫
  static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  static final String DB_URL = "jdbc:mysql://192.168.1.236:3306/aite?useSSL=false&serverTimezone=UTC";
  static final String USER = "root";
  static final String PASS = "c6f20omhhg";

  public static void main(String[] args) {
    // Connection conn = null;
    // Statement stmt = null;
    // Statement stmt2 = null;
    // try{
    //   Class.forName(JDBC_DRIVER);
    //   System.out.println("連接數(shù)據(jù)庫...");
    //   conn = DriverManager.getConnection(DB_URL,USER,PASS);
    //   System.out.println(" 實例化Statement對象...");
    //   stmt = conn.createStatement();
    //   String sql;
    //   sql = "SELECT id,id2 FROM sys_code_region where id2>736978";
    //   ResultSet rs = stmt.executeQuery(sql);
    //   int a=2;
    //   while(rs.next()){
    //     String id= rs.getString("id");
    //     //String name = rs.getString("id2");
    //     int b=rs.getInt("id2");
    //     String sql2;
    //     sql2= "update base_area set area_code="+id+" where id='"+b+"'";
    //     stmt2 = conn.createStatement();
    //     //stmt2.executeQuery(sql2);
    //     stmt2.execute(sql2);
    //     a++;
    //     System.out.print("ID: " + id);
    //     System.out.print(", id2: " + b);
    //     System.out.print("\n");
    //   }
    //   rs.close();
    //   stmt.close();
    //   conn.close();
    // }catch(SQLException se){
    //   se.printStackTrace();
    // }catch(Exception e){
    //   e.printStackTrace();
    // }finally{
    //  try{
    //     if(stmt!=null) stmt.close();
    //   }catch(SQLException se2){
    //   }
    //   try{
    //     if(conn!=null) conn.close();
    //   }catch(SQLException se){
    //     se.printStackTrace();
    //   }
    // }
    // System.out.println("Success!");

    //getPids();

    setPriority();
  }

  /**
   * pids查詢插入遞歸方法
   */
  public static void getPids(){
    Connection conn = null;
    Statement stmt = null;
    Statement stmt2 = null;
    String pids=null;
    try{
      Class.forName(JDBC_DRIVER);
      System.out.println("連接數(shù)據(jù)庫...");
      conn = DriverManager.getConnection(DB_URL,USER,PASS);
      System.out.println(" 實例化Statement對象...");
      stmt = conn.createStatement();
      String sql;
      sql = "SELECT id,pid,name FROM base_area where id=2210";
      ResultSet rs = stmt.executeQuery(sql);
      while(rs.next()){
        String str1=rs.getString("id");
        String str2=rs.getString("pid");
        String str3=rs.getString("name");
        int a =Integer.parseInt(str1);
        int b =Integer.parseInt(str2);
        pids=str2;
        int c=0;
        c=getPid(b);
        if (c>0){
          do{
            if (c >1) {
              pids = c + "," + pids;
              c = getPid(c);
            }
          }while (c>1);
          pids = c + "," + pids;
        }
        stmt2 = conn.createStatement();
        String sql2;
        sql2= "update base_area set pids='"+pids+"' where id="+a;
        stmt2.execute(sql2);
        System.out.println("id: "+a+",name:"+str3+", pids: "+pids);
      }
      rs.close();
      stmt.close();
      conn.close();
    }catch(SQLException se){
      se.printStackTrace();
    }catch(Exception e){
     e.printStackTrace();
    }finally{
      try{
        if(stmt!=null) stmt.close();
      }catch(SQLException se2){
      }
      try{
        if(conn!=null) conn.close();
      }catch(SQLException se){
        se.printStackTrace();
      }
    }
    System.out.println("Success!");
  }

  /**
   * pid 查詢方法
   * @param id
   * @return pid
   */
  public static Integer getPid(int id){
    Connection conn3 = null;
    Statement stmt3 = null;
    int pid =0;
    try{
    conn3= DriverManager.getConnection(DB_URL,USER,PASS);
    stmt3=conn3.createStatement();
    String sql3="select pid from base_area where id="+id;
    ResultSet rs3=stmt3.executeQuery(sql3);
    while (rs3.next()) {
      String str = rs3.getString("pid");
      pid = Integer.parseInt(str);
    }
      rs3.close();
      stmt3.close();
      conn3.close();
     }catch(SQLException se){
      se.printStackTrace();
    }catch(Exception e){
      e.printStackTrace();
    }finally{
      try{
        if(stmt3!=null) stmt3.close();
      }catch(SQLException se2){
      }
      try{
        if(conn3!=null) conn3.close();
      }catch(SQLException se){
        se.printStackTrace();
      }

    }
    return pid;
  }

  /**
   * 排序方法
   */
  public static void setPriority(){
    try {
      System.out.println("連接數(shù)據(jù)庫...");
      Connection conn4 = DriverManager.getConnection(DB_URL, USER, PASS);
      System.out.println(" 實例化Statement對象...");
      Statement stmt4 = conn4.createStatement();
      ResultSet rs4 = stmt4.executeQuery("select id from base_area ");
      while (rs4.next()){
        int id = rs4.getInt("id");
        Statement stmt5=conn4.createStatement();
        String sqlstr1="select id,pid from base_area where pid="+id+" ORDER BY id ";
        ResultSet rs5=stmt5.executeQuery(sqlstr1);
        rs5.last();
        int count=rs5.getRow();
        if(count>0) {
          rs5.beforeFirst();
          int i=1;
          while (rs5.next()) {
            int id2 = rs5.getInt("id");
            Statement stmt6 = conn4.createStatement();
            String sqlstr2="update base_area set priority=" + i + " where id=" + id2;
            stmt6.execute(sqlstr2);
            System.out.println("id:" + id2 + ", priority:" + i);
            i++;
          }
        }
        //System.out.println(id);
      }
    }
    catch (SQLException se){
      se.printStackTrace();
    }
    catch (Exception e){
       e.printStackTrace();
    }
     System.out.println("Complete!");
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • spring(java,js,html) 截圖上傳圖片實例詳解

    spring(java,js,html) 截圖上傳圖片實例詳解

    這篇文章主要介紹了spring(java,js,html) 截圖上傳圖片實例詳解的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • SpringCloud網(wǎng)關(guān)(Zuul)如何給多個微服務之間傳遞共享參數(shù)

    SpringCloud網(wǎng)關(guān)(Zuul)如何給多個微服務之間傳遞共享參數(shù)

    這篇文章主要介紹了SpringCloud網(wǎng)關(guān)(Zuul)如何給多個微服務之間傳遞共享參數(shù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • springboot如何實現(xiàn)異步響應請求(前端請求超時的問題解決)

    springboot如何實現(xiàn)異步響應請求(前端請求超時的問題解決)

    這篇文章主要給大家介紹了關(guān)于springboot如何實現(xiàn)異步響應請求(前端請求超時的問題解決)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,對大家學習或者使用springboot具有一定的參考學習價值,需要的朋友可以參考下
    2023-01-01
  • Java+MySQL實現(xiàn)圖書管理系統(tǒng)(完整代碼)

    Java+MySQL實現(xiàn)圖書管理系統(tǒng)(完整代碼)

    這篇文章主要介紹了Java+MySQL實現(xiàn)圖書管理系統(tǒng)(完整代碼),本文給大家介紹的非常想詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • 解決maven項目tomcat啟動失敗war exploded:Error during artifact deploym問題

    解決maven項目tomcat啟動失敗war exploded:Error during 

    在SpringMVC項目中,使用war和warexploded兩種部署方式可能會導致不同的路徑問題,從而出現(xiàn)404錯誤,war模式將項目打包上傳,而warexploded模式則保持文件夾結(jié)構(gòu)上傳,開發(fā)時建議使用warexploded模式,方便利用Update classes and resources功能自動更新
    2024-10-10
  • idea導入springboot項目沒有maven的解決

    idea導入springboot項目沒有maven的解決

    這篇文章主要介紹了idea導入springboot項目沒有maven的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • 基于Java編寫一個簡單的內(nèi)部網(wǎng)段掃描程序

    基于Java編寫一個簡單的內(nèi)部網(wǎng)段掃描程序

    這篇文章主要為大家詳細介紹了如何基于Java編寫一個簡單的內(nèi)部網(wǎng)段掃描程序,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起了解下
    2025-02-02
  • 遠程debug調(diào)試入門

    遠程debug調(diào)試入門

    這篇文章主要介紹了Eclipse的Debug調(diào)試技巧大全(總結(jié)),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧嗎,希望能給你帶來幫助
    2021-06-06
  • 使用mybatis切片實現(xiàn)數(shù)據(jù)權(quán)限控制的操作流程

    使用mybatis切片實現(xiàn)數(shù)據(jù)權(quán)限控制的操作流程

    數(shù)據(jù)權(quán)限控制需要對查詢出的數(shù)據(jù)進行篩選,對業(yè)務入侵最少的方式就是利用mybatis或者數(shù)據(jù)庫連接池的切片對已有業(yè)務的sql進行修改,本文給大家介紹了使用mybatis切片實現(xiàn)數(shù)據(jù)權(quán)限控制的操作流程,需要的朋友可以參考下
    2024-07-07
  • java中抽象類和接口的相同和不同點介紹

    java中抽象類和接口的相同和不同點介紹

    大家好,本篇文章主要講的是java中抽象類和接口的相同和不同點介紹,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12

最新評論

正定县| 梁山县| 巍山| 宣城市| 台州市| 黄山市| 将乐县| 措美县| 商城县| 宁武县| 龙游县| 平潭县| 阜康市| 台州市| 洛浦县| 长垣县| 固安县| 额济纳旗| 哈巴河县| 贵港市| 探索| 油尖旺区| 大埔县| 阳朔县| 喀喇| 海晏县| 调兵山市| 永丰县| 师宗县| 阜康市| 古交市| 万山特区| 淮南市| 马龙县| 古浪县| 女性| 石台县| 沙湾县| 藁城市| 石泉县| 喜德县|