数据库里的id是INT型的。
报错是;
The method setID(String) in the type ProductDetails is not applicable for the arguments (int)
14: //out.print(id);
15: ProductDetails item1=new ProductDetails();
16: item1.setContent(content);
17: item1.setID(id);
18: item1.setTitle(title);ProductDetails文件就是:
int id;
public int getID(){
return id;
}
public void setID(int id){
this.id=id;
}
编译过了。
怎么回事呢?

解决方案 »

  1.   

    id 没转换成int型..int id = Integer.parseInt(id);
      

  2.   

    晕了,这种问题,上面方法明明是String型的呀,你查一查看是不是引用错了,或者关掉开发工具再看,再不行重启电脑看看
      

  3.   

    17: item1.setID(id);
    你这里的id类型不是INT
      

  4.   

    是INT的,我转换了
    String idStr = request.getParameter("id");
    int id = Integer.parseInt(idStr);
      

  5.   

    17: item1.setID(id);
    改为: item1.setID(Integer.parseInt(id));
      

  6.   

    更新的方法是:
       public void update(ProductDetails item)throws Exception{
         String sql="update test_procdcts set content='"+item.getContent()+"' where id='+item.getID()+'";

    st.executeUpdate(sql);
       }
      

  7.   

    你用System.out("sql"+sql);把SQL输出到控制台看看,再把输出的SQL复制到数据库查询工具里面看看执行结果
      

  8.   

    我是这把那条语句放这的:
    public void update(ProductDetails item)throws Exception{
        String sql="update test_procdcts set content='"+item.getContent()+"' where id="+item.getID()+"";
     
         System.out.print("sql"+sql);
    st.executeUpdate(sql);
       }
    没有结果,空页面!?
      

  9.   

    控制台没有输出吗?如果是控制台没有输出那就应该是没有执行update()这个方法,你先查查有没有执行这个方法嘛
      

  10.   

    不过我突然想到,不应该没有输出的啊,就算sql为空,也应该输出前面的那个“sql”啊,是不是我放的地方有错?
      

  11.   

    是呀,没有输出最大的可能就是没有执行update()这个方法,你再在String sql=前面输出一些字符合看,如果还是没有输出,那就是肯定没有执行update()这个方法
      

  12.   

    恩,好。
    你有MSN吗?我们在那交流可以吗?可能以后还有很多问题要向你请教。
    我的是[email protected]
      

  13.   

    啊,我没有QQ了,你也是经常上网吧,弄一个可以吗?
    刚才我在String sql="update test_procdcts set content='"+item.getContent()+"' where id="+item.getID()+"";的上面也加了System.out.println("kfjkdj");
    可以还是没有输出啊?
      

  14.   

    那就是程序根本就没有执行到update()这个方法呀,你去查查你是在哪儿调用这个方法,看看在调用前是不是哪儿就错了,没有执行下去呀
      

  15.   

    ProductDetails item1=new ProductDetails();
    item1.setContent(content);
    item1.setID(Integer.parseInt(idStr));
    item1.setTitle(title);


    try{
    NewsProductBean bean1=new NewsProductBean();
    out.print(item1.getID);
    这个out.print(item1.getID);报错了,应该是item1没有值吧?
    报错是:
    An error occurred at line: 25 in the jsp file: /addpro.jsp
    item1.getID cannot be resolved or is not a field
    22: 
    23:  try{
    24:  NewsProductBean bean1=new NewsProductBean();
    25:  out.print(item1.getID);
      

  16.   

    不好意思,out.print(item1.getID);这里少个();
    那到这都可以执行了
    try{
    NewsProductBean bean1=new NewsProductBean();
    out.print(item1.getID());
    bean1.update(item1);是NewsProductBean类有问题吗?
      

  17.   

    id 没转换成int型..int id = Integer.parseInt(id);
      

  18.   

    这不可能吧,除非有两个ProductDetails类,着两个类的setID方法不一样