0

私のデータベースには 5 つの属性がありhashmap、struts2 プロジェクトでそれを取得しようとしています。属性の名前MarketPlaceは 、OrderDatedataamountcountresultです。ここでは、jsp テーブルの値を表示したいので、それぞれmarketplaceに 3 つのスパン行があり、値はdataamount, count,resultです。現在、私のJavaアクションクラスは次のようになっています。

package com.action;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.BreakIterator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.action.GetCon;
import com.action.ReportClass;

import freemarker.debug.Breakpoint;

public class JanuaryAction {
private String name;
HashMap abc = new HashMap();

public HashMap getAbc() {
return abc;
}
public void setAbc(HashMap abc) {
this.abc = abc;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public String execute() throws Exception{

String time=getName();
 /*   System.out.println(time);*/
if(time.equals("January 2013")){

abc.put(time,"'2013-01-01' AND OrderDate <= '2013-01-31'" );
}
else if(time.equals("February 2013")){
abc.put(time,"'2013-02-01' AND OrderDate <='2013-02-31'" );
}
else if(time.equals("March 2013")){
abc.put(time,"'2013-03-01' AND OrderDate <='2013-03-31'" );
}
else if(time.equals("April 2013")){
abc.put(time,"'2013-04-01' AND OrderDate <='2013-04-31'" );
}
else if(time.equals("May 2013")){
abc.put(time,"'2013-05-01' AND OrderDate <='2013-05-31'" );
}
else if(time.equals("June 2013")){
abc.put(time,"'2013-06-01' AND OrderDate <='2013-06-05'" );
}
String newtime=(String)abc.get(time);
   /* System.out.println(newtime);*/

Connection con = GetCon.getCon();
Statement statement = con.createStatement();
ResultSet resultset = statement.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >=" +newtime+ " GROUP BY OrderDate,MarketPlace") ;
Object value = abc.remove(time);

while(resultset.next()){

String marketplace = resultset.getString(1);

String orderdate = resultset.getString(2);

Double datamount = resultset.getDouble(3);
Integer count= resultset.getInt(4);

Double result=resultset.getDouble(5);

abc.put(0, marketplace);
String value1 = (String) abc.get(0);
System.out.println(value1);


abc.put(1, orderdate);
String value2 = (String) abc.get(1);
System.out.println(value2);


abc.put(2, datamount);
Double value3 = (Double) abc.get(2);
System.out.println(value3);


abc.put(3, count);
Integer value4 = (Integer) abc.get(3);
System.out.println(value4);


abc.put(4, result);
Double value5 = (Double) abc.get(4);
System.out.println(value5); }

return "success";
}}
4

1 に答える 1