MyException - 我的异常网
当前位置:我的异常网» J2EE » bean中取不到值,帮小弟我看一下有什么错了啊,多谢

bean中取不到值,帮小弟我看一下有什么错了啊,多谢

www.MyException.Cn  网友分享于:2013-12-07  浏览:163次
bean中取不到值,帮我看一下有什么错了啊,谢谢
UpstreamDao.java类
-----------------------------------------------------------------------
package com.xfy.dao.imple;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.xfy.dao.ifaec.IUpstream;
import com.xfy.tools.DBconnection;
import com.xfy.vo.UpstreamVO;

public class UpstreamDao implements IUpstream {

public List<UpstreamVO> getArrayList()
throws Exception {
ArrayList<UpstreamVO> arr=new ArrayList<UpstreamVO>();

String sql="select ORGADDR,SM_CONTENT,RECVTIME from TBL_SMRECEIVED";
Connection con=DBconnection.geConnection();
PreparedStatement ps=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs=ps.executeQuery();
while(rs.next()){
UpstreamVO up=new UpstreamVO();
up.setOrgaddr(rs.getString("ORGADDR"));
up.setRecvtime(rs.getDate("RECVTIME"));
up.setSM_content(rs.getString("SM_CONTENT"));
//System.out.println(rs.getString("ORGADDR"));
arr.add(up);
}
ps.close();
DBconnection.closeConnection();
return arr;
}
public static void main(String[] args) throws Exception {
IUpstream dao=new UpstreamDao();
UpstreamVO vo=new UpstreamVO();
List lst=dao.getArrayList();

System.out.println("sssssssssss"+lst.size());
for(int i=0;i<lst.size();i++)
System.out.println("电话号码:"+vo.getOrgaddr());
System.out.println("短信内容:"+vo.getSM_content());
System.out.println("接收时间:"+vo.getRecvtime());

}

}
----------------------------------------------------------------------
bean类
----------------------------------------------------------------------
package com.xfy.vo;

import java.util.Date;

public class UpstreamVO {
public String getOrgaddr() {
return orgaddr;
}
public void setOrgaddr(String orgaddr) {
this.orgaddr = orgaddr;
}
public String getSM_content() {
return SM_content;
}
public void setSM_content(String sMContent) {
SM_content = sMContent;
}
public Date getRecvtime() {
return recvtime;
}
public void setRecvtime(Date recvtime) {
this.recvtime = recvtime;
}
private String orgaddr;
private String SM_content;
private Date recvtime;
}

------解决方案--------------------
你这些程序的运行依赖于你其他的很多类,同时还有数据库的具体连接,这些你都没有给出无法检查你的数据获取过程十分合理,但是你main取数据的逻辑是有问题的,你先把main函数改一下
UpstreamDao你改成下面的代码试试看看有没有数据,有没有报异常
Java code

package com.xfy.dao.imple;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.xfy.dao.ifaec.IUpstream;
import com.xfy.tools.DBconnection;
import com.xfy.vo.UpstreamVO;

public class UpstreamDao implements IUpstream {

public List<UpstreamVO> getArrayList()
throws Exception {
ArrayList<UpstreamVO> arr=new ArrayList<UpstreamVO>();

String sql="select ORGADDR,SM_CONTENT,RECVTIME from TBL_SMRECEIVED";
Connection con=DBconnection.geConnection();
PreparedStatement ps=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs=ps.executeQuery();
while(rs.next()){
UpstreamVO up=new UpstreamVO();
up.setOrgaddr(rs.getString("ORGADDR"));
up.setRecvtime(rs.getDate("RECVTIME"));
up.setSM_content(rs.getString("SM_CONTENT"));
//System.out.println(rs.getString("ORGADDR"));
arr.add(up);
}
ps.close();
DBconnection.closeConnection();
return arr; 
}
public static void main(String[] args) throws Exception {
    IUpstream dao=new UpstreamDao();
    UpstreamVO vo=new UpstreamVO();
    List lst=dao.getArrayList();

    System.out.println("sssssssssss"+lst.size());
    for(int i=0;i<lst.size();i++){
    vo=lst.get(i);
    System.out.println("电话号码:"+vo.getOrgaddr());
    System.out.println("短信内容:"+vo.getSM_content());
    System.out.println("接收时间:"+vo.getRecvtime());
    }
}

}

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有