注册 登录
编程论坛 J2EE论坛

帮忙看一下哪里有错误没

zzg123 发布于 2009-08-13 11:32, 501 次点击
目的是在一个方法中执行4个SQL查询,然后生成的Excel表格调用这个方法,但是现在生成的表格里的值是空的,帮忙看下查询语句有错误没
        PreparedStatement selectStmt = null;
        Connection cn = null;
        ResultSet rs = null;
        
        PreparedStatement selectStmt2 = null;
        ResultSet rs2 = null;
        
        PreparedStatement selectStmt3 = null;
        ResultSet rs3 = null;
        
        PreparedStatement selectStmt4 = null;
        ResultSet rs4 = null;
        
        String[] reqId = limsIds.split(",");
        String[] str = new String[reqId.length+2];

        try {
            cn = getConnection(LIMS_DB_NAME);
            StringBuffer stmBuf = new StringBuffer(1000);
            stmBuf.append(STMT_SHQUFU);
            stmBuf.append(" and lims_id in ( " + limsIds + ")");
            selectStmt = cn.prepareStatement(stmBuf.toString());
            rs = selectStmt.executeQuery();

            while (rs.next()) {
                String limsId = "";
                limsId = String.valueOf(rs.getInt("lims_id"));
                if (limsId != null) {
                    for (int m = 0; m < reqId.length; m++) {
                        if (limsId.equals(reqId[m])) {
                                             str[m] = rs.getString("dataValue");                        }
                    }
                }
            }
             
        StringBuffer stmBuf2 = new StringBuffer(1000);
               stmBuf2.append(STMT_MAXLI);//STMT_MAXLI SQL语句
               stmBuf2.append(" and lims_id in ( " + limsIds + ")");
            selectStmt2 = cn.prepareStatement(stmBuf2.toString());
            rs2 = selectStmt2.executeQuery();            
            while (rs2.next()) {                
                String limsId2 = "";
                limsId2 = String.valueOf(rs2.getInt("lims_id"));
                if (limsId2 != null) {
                    for (int m = 0; m < reqId.length; m++) {
                        if (limsId2.equals(reqId[m])) {
                            str[m] = rs2.getString("dataValue");
                        }
                    }
                }
            }
           StringBuffer stmBuf3 = new StringBuffer(1000);
            stmBuf3.append(STMT_YUANSHI);//STMT_YUANSHI SQL语句
            stmBuf3.append(" and lims_id in ( " + limsIds + ")");
            selectStmt3 = cn.prepareStatement(stmBuf3.toString());
             rs3 = selectStmt3.executeQuery();            
            while (rs3.next()) {                
                String limsId3 = "";
                limsId3 = String.valueOf(rs3.getInt("lims_id"));
                if (limsId3 != null) {
                    for (int m = 0; m < reqId.length; m++) {
                        if (limsId3.equals(reqId[m])) {
                        str[m] = rs3.getString("dataValue");                        }
                    }
                }
            }
        StringBuffer stmBuf4 = new StringBuffer(1000);
        stmBuf4.append(STMT_DUANHOU);//STMT_DUANHOU SQL语句
            stmBuf4.append(" and lims_id in ( " + limsIds + ")");
            selectStmt4 = cn.prepareStatement(stmBuf4.toString());
            rs4 = selectStmt4.executeQuery();            
            while (rs4.next()) {                
                String limsId4 = "";
                limsId4 = String.valueOf(rs4.getInt("lims_id"));
                if (limsId4 != null) {
                    for (int m = 0; m < reqId.length; m++) {
                        if (limsId4.equals(reqId[m])) {
                            str[m] = rs4.getString("dataValue");
                         }
                    }
                }
            }
1 回复
#2
freish2009-08-13 15:19
在while循环中打印一下取出来的值不就知道了
1