注册 登录
编程论坛 J2EE论坛

关于list添加字符串的问题

czj11600 发布于 2010-02-11 19:34, 1185 次点击
怎么样用list 添加查询出来的字符串
比如
public class HoldDaoImpl implements IHoldDao {

    //通过用户的名字得到用户所买的股票名字
    public     List getUserHolding(int userid) {
        Connection conn=null;
        PreparedStatement pst=null;
        ResultSet rs=null;
        List list=new ArrayList();
        try{
            conn=ConnectionFactory.getConnection();
            String sql="select name from stock where stock_id=(" +
                    "select stock_id from holding where user_id=?)";
            pst=conn.prepareStatement(sql);
            pst.setInt(1, userid);
            rs=pst.executeQuery();
            while(rs!= null && rs.next()){
              这里怎样用list添加查询出来的name值
                    ??????
                    ??????
                    
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            ConnectionFactory.closeResultSet(rs);
            ConnectionFactory.closePreparedStatement(pst);
            ConnectionFactory.closeConnection(conn);
        }

        return list;
    }
4 回复
#2
czj116002010-02-11 19:44
各位大虾帮帮忙
#3
lampeter1232010-02-11 20:17
用list.add()方法
#4
czj116002010-02-11 20:28
list.add只能加对象吧,我试了eclipse 一直报错
#5
sbihcmfkpgf2010-02-12 10:13
list.add(new String(rs.getString(1)));
1