数组存储问题

cc_happy 2009-09-20 10:58:29

/**
* 把字符串解析成日期格式
* @param temp 格式为:2009-05-12 11:30 解析成 0905121130形式
* @return yyyy-mm-dd hh:mi
*/
public String getTime(String temp){

StringBuffer result = new StringBuffer();
if(temp!=null&&!temp.equals("")){
result.append(temp.substring(2,4));
result.append(temp.substring(5,7));
result.append(temp.substring(8,10));
result.append(temp.substring(11,13));
result.append(temp.substring(14,temp.length()));
}
return result.toString();
}
/* 计算字符串str中,symbol中出现在次数
* @param str
* @param symbol
*/
public int caculateSymbolQuantity(String str,String symbol){
String temp= str;
int i=0,n=0;//n存储符号出现的次数
i = temp.indexOf(symbol);
while(i!=-1){
temp=temp.substring(i+1,temp.length());
n++;
i = temp.indexOf(symbol);
}
return n;
}
public List getPlace(String place){
List result = new ArrayList();
String temp = "";
if(place!=null&&!place.equals("")){
int i = place.lastIndexOf(",");
if(i!=place.length()-1){//如果最后一位不是","号,则以","结尾
temp=place+",";
}else{
temp=place;
}
int n = caculateSymbolQuantity(temp,",");//计算该字符串中出现的","的个数
System.out.println("-------------n is :"+n);
int count = n/3;
String[] temps = place.split(",");
for(int j = 1; j <= count;j++){
result.add(temps[j*3-3]+","+temps[j*3-2]+","+temps[j*3-1]);//存的数据形式为:333,444,555
System.out.println(temps[j*3-3]+","+temps[j*3-2]+","+temps[j*3-1]);
}

}//if


return result;
}



public String save(){
///////////从前台获取的place的值是:95302,0,2009-09-18 10:51,01002,0,2009-09-25 10:52,01002,0,2009-09-03 10:52,
String place = request.getParameter("subName");
String ways = request.getParameter("subNameW");
//cr.setPlace(place);
cr.setRoute_way(ways);

String way [] = ways.split(","); //这里就是所有的值了
List l =getPlace(place);
Iterator it = l.iterator();
while(it.hasNext()){
String str_place = (String)it.next();

String[] places = str_place.split(",");
cr.setArea_name(places[0]); //接货地点编码
cr.setTakeOver_style(places[1]); //接货地点方式,市内还是市外
cr.setStop_time(getTime(places[2])); //停靠时间
cr.setPlace(places[0]+","+places[1]+","+getTime(places[2]));
System.out.println(places);
System.out.println("000000000000000000 place:"+places[0]+","+places[1]+","+places[2]);


}//if
carRouteService.saveData(cr);
return "close";
}





我最后想存到数据库里的应该是:95302,0,0909181051,01002,0,0909251052,01002,0,0909031052
可是照我这样的存法只能存一组如(01002,0,0909031052
).. 闷请高手指点下怎么能都存进去 谢谢
...全文
47 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yztommyhc 2009-09-20
  • 打赏
  • 举报
回复
定位这种问题其实是相对简单的:

检查你的数组的长度是多少,加入你的数组长度就是一,那么入库的数据量当然是一了。

在关键的地方打印一些数据(比如数组长度),或者使用工具的debug功能。

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧