![](/img/trans.png)
[英]Iterate through a dynamically created table and Insert data into SQL Server table
[英]Insert into SQL table data from another table data through NetBeans
我想通过NetBeans从另一个SQL表数据中插入SQL表数据。 我想要当我想按动作按钮时,它应该从SQL表(EventLog)插入到SQL表数据(insertdata2)中。
表1:EventLog EventId(int)ObjectId(varchar 50)名称(varchar 50)值(varchar 50)
表2:insertdata2 Id(int)ObjectId(varchar 50)名称(Varchar 50)值(varchar50)
这是我的按钮代码:
DoConnect();
st=conn.createStatement();
rs=st.executeQuery("insert into insertdata2 (ObjectId,insertdata2.Name,insertdata.Value) select top 5 EventLog.ObjectId,EventLog.Name,EventLog.Value from EventLog order by EventId desc");
rs=st.executeQuery("select top 50 EventId,ObjectId,Name,Value from insertdata2 order by Id desc ");
jTable1.setModel(net.proteanit.sql.DbUtils.resultSetToTableModel(rs)); }
catch(Exception e){
JOptionPane.showMessageDialog(null,e); }
但是显示错误:“该语句未返回结果集”
就是这个 触发insert
时应使用executeUpdate()
。 因此,您可以尝试执行以下操作:
final String INSERT_SQL =
"insert into insertdata2 (ObjectId,insertdata2.Name,insertdata.Value) select top 5 EventLog.ObjectId,EventLog.Name,EventLog.Value from EventLog order by EventId desc";
connection.prepareStatement(INSERT_SQL).executeUpdate();
rs=st.executeQuery("select top 50 EventId,ObjectId,Name,Value from insertdata2 order by Id desc ");
并不是我在选择新数据之前已经执行了insert
SQL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.