Iterator iter1 = t.iterator();
while(iter1.hasNext()){
rowid1 = iter1.next();
if (!t1.contains(rowid1)){
System.out.println(rowid1);
Statement st1=con.createStatement();
st1.executeQuery("Select * from table1 where rowid="+rowid1+""); //plz anybody corrct the query if it is logic then that too
Statement st = con1.createStatement();
st.executeUpdate("insert into table2 values("+rowid1+")";
}
}
}
最后插入prtion显示错误消息,请帮我纠正查询。我想插入整行意味着假设rowid是21,有很多colums,这在table2中不存在,所以整个colum值需要动态插入第21行请帮帮我。
答案 0 :(得分:0)
你似乎缺少一个括号......它应该是......
st.executeUpdate("insert into table2 values("+rowid1+")");
您的问题表明您希望将记录从一个表复制到另一个表中的另一个表。您可以为每个数据库创建两个连接对象。
Statement st1 = con1.createStatement();
ResultSet rs = st1.executeQuery("select * from table1");
PreparedStatement ps = null;
while(rs.next())
{
ps = con2.prepareStatement("insert into table2 values(?,?)");
ps.setInt(rs.getInt());
ps.setString(rs.getString());
}
/ 我假设你的表中有两列 /