m756028276 2014-12-14 10:33 采纳率: 50%
浏览 7355
已采纳

SQLServerException: 没有为参数号 1 设置值。

public List getAllNotice(){
    Connection con=null;
    PreparedStatement stm=null;
    ResultSet rs=null;
    List list=new ArrayList();

    try{
        con=ConnectionManager.getConnection();
        String sql="select * from notice where ntype=?";
        stm=con.prepareStatement(sql);
        rs=stm.executeQuery();
        while(rs.next()){
            int no=rs.getInt("Nno");
            String title=rs.getString("Ntitle");
            Notice notice=new Notice(no);
            notice.setId(no);
            notice.setTitle(title);
            list.add(notice);
        }
    }catch(Exception e){
        e.printStackTrace();
    }finally{
        ConnectionManager.closeResultSet(rs);
        ConnectionManager.closeStatement(stm);
        ConnectionManager.closeConnection(con);
    }
    return list;
}

这个问题出在哪里了?
  • 写回答

2条回答 默认 最新

  • devmiao 2014-12-14 10:55
    关注

    String sql="select * from notice where ntype=?";
    stm=con.prepareStatement(sql);
    stm.setInt(1, 参数); //给ntype一个参数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程