欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

import java.sql.*;

public class Main {
   //本地?cái)?shù)據(jù)庫(kù)
  // 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";

  //測(cè)試服務(wù)器數(shù)據(jù)庫(kù)
  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ù)庫(kù)...");
    //   conn = DriverManager.getConnection(DB_URL,USER,PASS);
    //   System.out.println(" 實(shí)例化Statement對(duì)象...");
    //   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ù)庫(kù)...");
      conn = DriverManager.getConnection(DB_URL,USER,PASS);
      System.out.println(" 實(shí)例化Statement對(duì)象...");
      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ù)庫(kù)...");
      Connection conn4 = DriverManager.getConnection(DB_URL, USER, PASS);
      System.out.println(" 實(shí)例化Statement對(duì)象...");
      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!");
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot利用validation實(shí)現(xiàn)優(yōu)雅的校驗(yàn)參數(shù)

    SpringBoot利用validation實(shí)現(xiàn)優(yōu)雅的校驗(yàn)參數(shù)

    數(shù)據(jù)的校驗(yàn)是交互式網(wǎng)站一個(gè)不可或缺的功能,如果數(shù)據(jù)庫(kù)中出現(xiàn)一個(gè)非法的郵箱格式,會(huì)讓運(yùn)維人員頭疼不已。本文將介紹如何利用validation來(lái)對(duì)數(shù)據(jù)進(jìn)行校驗(yàn),感興趣的可以跟隨小編一起學(xué)習(xí)一下
    2022-06-06
  • Spring boot2基于Mybatis實(shí)現(xiàn)多表關(guān)聯(lián)查詢

    Spring boot2基于Mybatis實(shí)現(xiàn)多表關(guān)聯(lián)查詢

    這篇文章主要介紹了Spring boot2基于Mybatis實(shí)現(xiàn)多表關(guān)聯(lián)查詢,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • Java比較對(duì)象大小兩種常用方法

    Java比較對(duì)象大小兩種常用方法

    這篇文章主要介紹了Java比較對(duì)象大小兩種常用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • SpringCloud啟動(dòng)失敗問(wèn)題匯總

    SpringCloud啟動(dòng)失敗問(wèn)題匯總

    這篇文章主要介紹了SpringCloud啟動(dòng)失敗問(wèn)題匯總,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • 編寫Java代碼制造一個(gè)內(nèi)存溢出的情況

    編寫Java代碼制造一個(gè)內(nèi)存溢出的情況

    這篇文章主要介紹了編寫Java代碼制造一個(gè)內(nèi)存溢出的情況,或許這種有意制造能夠更好地幫助理解Java中的內(nèi)存溢出情況XD 需要的朋友可以參考下
    2015-07-07
  • Maven安裝與配置及Idea配置Maven的全過(guò)程

    Maven安裝與配置及Idea配置Maven的全過(guò)程

    Maven是一個(gè)項(xiàng)目管理工具,可以對(duì)Java項(xiàng)目進(jìn)行自動(dòng)化的構(gòu)建和依賴管理,下面這篇文章主要給大家介紹了關(guān)于Maven安裝與配置及Idea配置Maven的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • Java中GC與四種引用的關(guān)系詳解

    Java中GC與四種引用的關(guān)系詳解

    這篇文章主要介紹了Java中GC與四種引用的關(guān)系詳解,Java 中一共有 4 種類型的引用 : StrongReference、 SoftReference、 WeakReference 以及 PhantomReference這 4 種類型的引用與 GC 有著密切的關(guān)系, 讓我們逐一來(lái)看它們的定義和使用場(chǎng)景,需要的朋友可以參考下
    2023-09-09
  • 使用javafx更新UI的方法

    使用javafx更新UI的方法

    這篇文章主要介紹了使用javafx更新UI的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • IntelliJ IDEA中查看當(dāng)前類的所有繼承關(guān)系圖

    IntelliJ IDEA中查看當(dāng)前類的所有繼承關(guān)系圖

    今天小編就為大家分享一篇關(guān)于IntelliJ IDEA中查看當(dāng)前類的所有繼承關(guān)系圖,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2018-10-10
  • ssm項(xiàng)目改造spring?boot項(xiàng)目完整步驟

    ssm項(xiàng)目改造spring?boot項(xiàng)目完整步驟

    Spring?Boot現(xiàn)在已經(jīng)成為Java開發(fā)領(lǐng)域的一顆璀璨明珠,它本身是包容萬(wàn)象的,可以跟各種技術(shù)集成,下面這篇文章主要給大家介紹了關(guān)于ssm項(xiàng)目改造spring?boot項(xiàng)目的相關(guān)資料,需要的朋友可以參考下
    2023-04-04

最新評(píng)論