基础问题,在线等待!急..... 是字符串不定长?还是数组不定长???若是字符串不定长可以使用StringBuffer,若是数组不定长可以利用ArrayList 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的bean中代码如下: public String[][] getMonthReport(Statement Stmt, String Year, String Month, String UnitID) throws SQLException { ResultSet RS=null; int cnt=0, i=0, s_cnt=0, arrayMax=0, month=0; String zjrq="", FLID="", sqlStr=""; month = Integer.parseInt(Month); zjrq = Year + Month + "01"; //System.out.println("&&&&&&&&&&&&&&&&&&&&Years:" + zjrq); //########################## //取得数组的下标 try { sqlStr="select count(distinct FLID) as cnt From Depreciate Where DW='" + UnitID + "'"; RS=Stmt.executeQuery(sqlStr); RS.next(); cnt=RS.getInt("cnt"); RS.close(); } catch(Exception e){System.out.println("Depreciate.java-->getMonthReport():" + e.toString());} //声明返回数组 arrayMax = cnt + 1; //最后一行为累计值,初始化数组 //System.out.println("Depreciate.java--ArrayMax:" + arrayMax); //############################### String MonthData[][] = new String [arrayMax][6]; float CountData[] = new float[3]; for(i=0; i<arrayMax; i++) { //System.out.println("Depreciate.java-->Init-i:" + i); //################################## MonthData[i][0]="0.00"; MonthData[i][1]="0.00"; MonthData[i][2]="0.00"; MonthData[i][3]="0.00"; MonthData[i][4]="0.00"; MonthData[i][5]="0.00"; } CountData[0] = 0; CountData[1] = 0; CountData[2] = 0; try { sqlStr = "select FLID,NZhJL,sum(ZhJE" + month + ") as ZhJE" + ",sum(YZh" + month + ") as YZh From Depreciate Where DW='" + UnitID + "' group by FLID order by FLID"; //System.out.println("Depreciate.java-->SqlStr:" + sqlStr); //################################## RS=Stmt.executeQuery(sqlStr); i=0; while(RS.next()) //分类别统计折旧信息 { //System.out.println("Depreciate.java-->i:" + i); //################################## MonthData[i][0] = RS.getString("FLID"); MonthData[i][2] = String.valueOf(RS.getFloat("YZh")); MonthData[i][3] = RS.getString("NZhJL"); MonthData[i][4] = String.valueOf(RS.getFloat("ZhJE")); CountData[0]=CountData[0] + RS.getFloat("YZh"); //原值合计值 CountData[1]=CountData[1] + RS.getFloat("ZhJE"); //折旧额合计值 i++; } RS.close(); //填充“用于计提折旧原值” for (i=0; i<arrayMax-1; i++) { sqlStr="Select ZChLB,sum(YZh) as YZh From Card Where ZhT='运行' and ZhJJZhRQ>='" + zjrq + "' and substring(ID,9,2)='" + UnitID + "' And FLID='" + MonthData[i][0] + "' Group By FLID"; //System.out.println("Depreciate.java-->SqlStr:" + sqlStr); //############################# RS=Stmt.executeQuery(sqlStr); RS.next(); MonthData[i][1] = RS.getString("ZChLB"); //System.out.println("Depreciate.java-->ZChLB:" + RS.getString("ZChLB")); //############################# MonthData[i][5] = String.valueOf(RS.getFloat("YZh")); //用于计提折旧原值 CountData[2]=CountData[2] + RS.getFloat("YZh"); //合计(用于计提折旧原值) RS.close(); } MonthData[arrayMax-1][0] = String.valueOf(CountData[0]); //合计(原值) MonthData[arrayMax-1][1] = String.valueOf(CountData[1]); //合计(折旧额) MonthData[arrayMax-1][2] = String.valueOf(CountData[2]); //合计(用于计提折旧原值) }catch(Exception e){System.out.println(e.toString());} return MonthData; } jsp中:String Data[][] = Dep.getMonthReport(Stmt, Year, Month, UnitID);int RowCount = Data.length;for (int i=0; i<RowCount-1; i++) {out.println(Data[i][0]);} 使用tomcat数据源 错误 求救!!!!! java如何生成分页的html 请教大虾们一个问题 95317312 请问:在JSP里怎么实现登陆验证(连接数据库)? JSP页面如何大量取得客户端的数据。 weblogic下运行servlet问题 关于jsp处理中文输入。在线等待,急!!!!!!!! JBuilder 8 不能保存JSP文件! tomcat+jsp sql7 中正常显示中文,2000就是乱码,何故? weblogic7+jb7如何调试jsp页面?送分!!!!!!!!!!! java与sqlserver数据库的连接类
public String[][] getMonthReport(Statement Stmt, String Year, String Month, String UnitID) throws SQLException
{
ResultSet RS=null;
int cnt=0, i=0, s_cnt=0, arrayMax=0, month=0;
String zjrq="", FLID="", sqlStr=""; month = Integer.parseInt(Month); zjrq = Year + Month + "01";
//System.out.println("&&&&&&&&&&&&&&&&&&&&Years:" + zjrq); //##########################
//取得数组的下标
try
{
sqlStr="select count(distinct FLID) as cnt From Depreciate Where DW='" + UnitID + "'";
RS=Stmt.executeQuery(sqlStr);
RS.next();
cnt=RS.getInt("cnt");
RS.close();
}
catch(Exception e){System.out.println("Depreciate.java-->getMonthReport():" + e.toString());}
//声明返回数组
arrayMax = cnt + 1; //最后一行为累计值,初始化数组
//System.out.println("Depreciate.java--ArrayMax:" + arrayMax); //###############################
String MonthData[][] = new String [arrayMax][6];
float CountData[] = new float[3];
for(i=0; i<arrayMax; i++)
{
//System.out.println("Depreciate.java-->Init-i:" + i); //##################################
MonthData[i][0]="0.00"; MonthData[i][1]="0.00"; MonthData[i][2]="0.00";
MonthData[i][3]="0.00"; MonthData[i][4]="0.00"; MonthData[i][5]="0.00";
}
CountData[0] = 0; CountData[1] = 0; CountData[2] = 0;
try
{
sqlStr = "select FLID,NZhJL,sum(ZhJE" + month + ") as ZhJE" + ",sum(YZh" + month +
") as YZh From Depreciate Where DW='" + UnitID + "' group by FLID order by FLID";
//System.out.println("Depreciate.java-->SqlStr:" + sqlStr); //##################################
RS=Stmt.executeQuery(sqlStr);
i=0;
while(RS.next()) //分类别统计折旧信息
{
//System.out.println("Depreciate.java-->i:" + i); //##################################
MonthData[i][0] = RS.getString("FLID"); MonthData[i][2] = String.valueOf(RS.getFloat("YZh"));
MonthData[i][3] = RS.getString("NZhJL"); MonthData[i][4] = String.valueOf(RS.getFloat("ZhJE"));
CountData[0]=CountData[0] + RS.getFloat("YZh"); //原值合计值
CountData[1]=CountData[1] + RS.getFloat("ZhJE"); //折旧额合计值
i++;
}
RS.close();
//填充“用于计提折旧原值”
for (i=0; i<arrayMax-1; i++)
{
sqlStr="Select ZChLB,sum(YZh) as YZh From Card Where ZhT='运行' and ZhJJZhRQ>='" + zjrq +
"' and substring(ID,9,2)='" + UnitID + "' And FLID='" + MonthData[i][0] + "' Group By FLID";
//System.out.println("Depreciate.java-->SqlStr:" + sqlStr); //#############################
RS=Stmt.executeQuery(sqlStr); RS.next();
MonthData[i][1] = RS.getString("ZChLB");
//System.out.println("Depreciate.java-->ZChLB:" + RS.getString("ZChLB")); //#############################
MonthData[i][5] = String.valueOf(RS.getFloat("YZh")); //用于计提折旧原值
CountData[2]=CountData[2] + RS.getFloat("YZh"); //合计(用于计提折旧原值)
RS.close();
}
MonthData[arrayMax-1][0] = String.valueOf(CountData[0]); //合计(原值)
MonthData[arrayMax-1][1] = String.valueOf(CountData[1]); //合计(折旧额)
MonthData[arrayMax-1][2] = String.valueOf(CountData[2]); //合计(用于计提折旧原值)
}catch(Exception e){System.out.println(e.toString());}
return MonthData;
}
jsp中:
String Data[][] = Dep.getMonthReport(Stmt, Year, Month, UnitID);
int RowCount = Data.length;
for (int i=0; i<RowCount-1; i++)
{out.println(Data[i][0]);}