Stored Procedures

      在〈Stored Procedures〉中尚無留言

在android調用procedures的方法如下

private void query(){
    try {
        conn = DriverManager.getConnection(String.format("jdbc:mysql://%s/%s", G.dbHost, G.database), G.dbAccount, G.dbPassword);
        PreparedStatement preStmt = conn.prepareStatement(String.format("call 單日日報表查詢('%s')", day));
        ResultSet rs = preStmt.executeQuery();
        dailyInfo=new ArrayList<>();
        while (rs.next()) {
            String loraAddress="", loraHosiery="", mcName="";
            String loraId[]=rs.getString("id").split("\\^_\\^");
            loraAddress=loraId[0];
            if(loraId.length>1)loraHosiery=loraId[1];
            Statement stmt=conn.createStatement();
            ResultSet mRs=stmt.executeQuery(String.format("select * from machine where mc_ip1*256+mc_ip2='%s'", loraAddress));
            if(mRs.next()){
                mcName=mRs.getString("mc_name");
            }
            Map<String, String>row=new TreeMap<>();
            row.put("MACHINE", mcName);
            row.put("HOSIERY", loraHosiery);
            row.put("MORNING", rs.getString("morning"));
            row.put("NOON", rs.getString("noon"));
            row.put("NIGHT", rs.getString("night"));
            row.put("ALLDAY", rs.getString("allDay"));
            dailyInfo.add(row);
        }
    }
    catch(SQLException e){Log.d("Thomas", "aaa"+e.getMessage());}
    handler.sendEmptyMessage(DATABASE_QUERY_SUCCESS);
}

todo

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *