如何在DAO类中将选定数据从一个表输入到另一个表? [英] How do I enter selected data from one table to another table in DAO class?
问题描述
public boolean registerCustomer(CustomerBean obj)
{
String sql1;
PreparedStatement ps = null;
尝试{
sql1 =插入注册值(?,?,?,?); //注册工作正常
ps = conn.prepareStatement(sql1 );
ps.setString(1,obj.getName());
ps.setString(2,obj.getEmailId());
ps.setString(3,obj.getPassword());
ps.setString(4,obj.getCountry());
int ret = ps.executeUpdate (); //这里我想将电子邮件ID和密码发送到另一个表格
if(ret> 0){
conn.commit();
返回true;
}
} catch(SQLException sqe){
sqe.printStackTrace();
}
返回false;
}
我的尝试:
我尝试在executeUpdate()之后再次使用insert语句。但它不起作用。
public boolean registerCustomer(CustomerBean obj)
{
String sql1;
PreparedStatement ps = null;
try {
sql1 = "INSERT into Registration values(?,?,?,?)";//registration is working Fine
ps = conn.prepareStatement(sql1);
ps.setString(1, obj.getName());
ps.setString(2, obj.getEmailId());
ps.setString(3, obj.getPassword());
ps.setString(4, obj.getCountry());
int ret = ps.executeUpdate();//here I want to send Email id and Password to another table
if(ret > 0) {
conn.commit();
return true;
}
} catch(SQLException sqe) {
sqe.printStackTrace();
}
return false;
}
What I have tried:
I tried to use insert Statement again after executeUpdate(). But it doesn't work.
推荐答案
看到这个
see this
public boolean registerCustomer(CustomerBean obj)
{
String sql1;
PreparedStatement ps = null;
try {
sql1 = "INSERT into Registration values(?,?,?,?)";//registration is working Fine
ps = conn.prepareStatement(sql1);
ps.setString(1, obj.getName());
ps.setString(2, obj.getEmailId());
ps.setString(3, obj.getPassword());
ps.setString(4, obj.getCountry());
int ret = ps.executeUpdate();//here I want to send Email id and Password to another table
if(ret > 0) {
conn.commit();
return true;
}
//update line
sql1 = "INSERT into AnotherRegistration values(?,?)";//registration is working Fine
ps = conn.prepareStatement(sql1);
ps.setString(2, obj.getEmailId());
ps.setString(3, obj.getPassword());
int ret = ps.executeUpdate();
if(ret > 0) {
conn.commit();
return true;
}
} catch(SQLException sqe) {
sqe.printStackTrace();
}
return false;
}
这篇关于如何在DAO类中将选定数据从一个表输入到另一个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!