Statemane.setint(1,cat_id)
写道前面。
赋值给sql
^_^

解决方案 »

  1.   

    你的写法有问题
    int cat_id = 0;
    String sql = "select * from catalog where catid=?";
    PreparedStatement pstmt = connection.prepareStatement(sql);
    pstmt.setInt(1,cat_id);
    ResultSet rs=pstmt.executeQuery(sql);
    .....
      

  2.   

    statement.setInt(1);
    已经得到了所有的参数,再加一个cat_id可能不认识了,我理解的,不知道对否
      

  3.   

    对不起,是我写错了我的顺序是按后来大家所说的,报的错是"并非所有变量都已关联"如果按我最开始那个顺序,则报null错
      

  4.   

    从发程序:这个才是元程序        Connection connection=null;
            PreparedStatement statement = null; 
            CatalogMsg m = new CatalogMsg();
            try{
                //String sql = "select * from catalog where catid="+cat_id;
                String sql = "select * from catalog where catid=?";
                connection=jdbcMgr.getConnection();
                statement=connection.prepareStatement(sql);
                statement.setInt(1,cat_id);
                
                ResultSet rs=statement.executeQuery(sql);
                if (rs.next())
                {
                    m.setCatID(rs.getInt("catid"));
                    m.setParent(rs.getInt("parent"));
                    m.setCatName(rs.getString("catName"));
                    m.setCatDesc(rs.getString("catdesc"));
                    m.setPos(rs.getInt("pos"));
                    m.setCatDate(rs.getString("catDate"));    
                }
                
            }