1, 將數據從db中讀取出來, 形成數據集
網站建設哪家好,找創(chuàng)新互聯(lián)公司!專注于網頁設計、網站建設、微信開發(fā)、成都微信小程序、集團企業(yè)網站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了振興免費建站歡迎大家使用!
2, 將數據集賦值給Echarrs圖表
讀取數據庫,首先要將數據庫的驅動包導入:如果是mysql數據庫,需要導入mysql-connector-java-5.1.27.jar,如果是oracle就需要導入oracle.jar包;
然后就是建立數據庫連接,使用Connection 新建連接,然后執(zhí)行你的sql語句查詢出需要的數據,下面是兩個方法: 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是文件存儲的,只用將數據庫安裝目錄下的data下的數據庫名稱文件夾拷貝出來就相當于數據庫備份了,然后你在目標機上重新安裝mysql數據庫,再將該數據庫文件拷貝到相應的data目錄下即可。