十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
1, 將數(shù)據(jù)從db中讀取出來, 形成數(shù)據(jù)集
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、成都微信小程序、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了振興免費建站歡迎大家使用!
2, 將數(shù)據(jù)集賦值給Echarrs圖表
讀取數(shù)據(jù)庫,首先要將數(shù)據(jù)庫的驅(qū)動包導(dǎo)入:如果是mysql數(shù)據(jù)庫,需要導(dǎo)入mysql-connector-java-5.1.27.jar,如果是oracle就需要導(dǎo)入oracle.jar包;
然后就是建立數(shù)據(jù)庫連接,使用Connection 新建連接,然后執(zhí)行你的sql語句查詢出需要的數(shù)據(jù),下面是兩個方法: public PageModel findAllUser(int pageNo,int pageSize){String sql = "select * from user where user_name 'root' order by user_name" +"limit" + (pageNo - 1) * pageSize + "," + pageSize;PageModel pageModel =null;Connection conn =null;Statement stmt =null;ResultSet rs = null;try{conn = DB.getConn();stmt = conn.createStatement();rs = stmt.executeQuery(sql);List user_List = new ArrayList();while(rs.next()){User user = new User();user.setUser_name(rs.getString("user_name"));user.setUser_password(rs.getString("user_password"));user.setUser_tel(rs.getString("user_tel"));user.setUser_email(rs.getString("user_email"));user.setUser_createDate(rs.getTimestamp("user_createdate"));user_List.add(user);}//取得所有記錄int totalRecords = getTotalRecords(conn);pageModel = new PageModel();pageModel.setPageSize(pageSize);pageModel.setList(user_List);pageModel.setTotalRecord(totalRecords);}catch(SQLException e){e.printStackTrace();}finally{DB.close(rs);DB.close(stmt);DB.close(conn);}return pageModel;} /** * 取得所有記錄 * @param conn * @return 所有記錄totalRecords */public int getTotalRecords(Connection conn){String sql = "select count(*) from user where user_name 'root' ";int totalRecords = 0;Statement stmt = null;ResultSet rs = null;try{conn = DB.getConn();stmt = conn.createStatement();rs = stmt.executeQuery(sql);if(rs.next()){totalRecords = rs.getInt(1);}}catch(SQLException e){e.printStackTrace();}finally{DB.close(rs);DB.close(stmt);DB.close(conn);}return totalRecords;}
mysql是文件存儲的,只用將數(shù)據(jù)庫安裝目錄下的data下的數(shù)據(jù)庫名稱文件夾拷貝出來就相當于數(shù)據(jù)庫備份了,然后你在目標機上重新安裝mysql數(shù)據(jù)庫,再將該數(shù)據(jù)庫文件拷貝到相應(yīng)的data目錄下即可。