【问题标题】:inserting a row from one table to another in mysql on clicking a hyperlink在单击超链接时在mysql中将一行从一个表插入另一个表
【发布时间】:2014-03-19 06:17:33
【问题描述】:

我有一个在网站上注册的用户列表,当管理员单击批准时,必须将其插入另一个名为 login 的表中。我有代码,它没有抛出任何异常或任何错误,但它根本没有将行数据从一个表传输到另一个表。

下面是我的servlet:

还有我的 DAO:

PreparedStatement ps=conn.prepareStatement("insert into login(id,FirstName,LastName,Gender,Category,Dateofbirth,Age,Address,Country,State,city,PinCode,EmailId,ContactNo,MobileNo)select * from register where id=?");
            ps.setInt(1, id);
            ps.executeUpdate();
        }

请有人帮我解决这个问题,在此先感谢。

【问题讨论】:

  • 不用谢谢,我只是编辑列车的最后一站。其他人(点击“已编辑”链接了解详细信息)首先帮助了您。
  • 你能检查你的 id 是否得到查询吗?你得到哪个错误或异常?仅尝试直接针对您的数据库进行该查询并确认它是否有效。
  • 没有错误或异常被抛出......它只是没有从一个表移动到另一个
  • approve.clientApprove(id); 如果你怀疑这里.. 你检查过try and catch 块吗?你确定 Query 正在你的数据库上工作并且register 表的列数与login 表的列数相同吗?
  • 对不起,我是个新手,你能告诉我如何通过单独执行来检查查询是否在数据库上工作吗??

标签: java mysql jakarta-ee spring-mvc


【解决方案1】:

好的,如果是getter of parameter Id,该变量的声明不应该是这样的 我对spring MVC不太了解,但是getter声明应该是这样的

 private int id;/ * This is the parameter you are expecting from Front End 
 public int getId()//*This is the getter of that parameter.
 {
    return id;   
 }
 public void setId(int id)//Setter of ID parameter which sets the ID value to the local ID parameter
 {  
      this.id = id;

  }

``

在您的代码中,您正在为client 类创建新对象,并为参数调用getter 方法。我的意思是id 参数设置在client 类的不同对象中,并且您正在使用其他类中新创建的getId() 调用该方法。 我不知道它在spring 中是如何工作的,通常在MVC 框架中Every fomr will be related to a bean 在那个bean 中你将有settergetters 用于表单中的字段.. 所以我建议你尝试使用特定形式的确切对象,在那里你可以获得id参数的值

【讨论】:

  • **ya 它和我所做的一样......我忘了在顶部发布 id 声明......比如 ** int id; public int getId() { return id; } public void setId(int id) { this.id = id; }
  • 你可以部分理解,但你所说的特定形式的确切对象是什么意思?你的意思是说特定形式的特定bean的对象??
  • tutorialspoint.com/spring/spring_mvc_form_handling_example.htm 在这个例子中.. Student.javabean 在控制器类中getters of parameters 的调用请参考
  • 虽然我不能完美地得出结论,但我从你的帖子中学到了很多,感谢你如此谦虚@looser
  • 你的意思是和这个相关的新问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
  • 2012-12-05
  • 2017-01-24
  • 2015-07-02
相关资源
最近更新 更多