问题描述
我想通过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); }
但是显示错误:“该语句未返回结果集”
1楼
Rhuan Karlus
0
已采纳
2019-02-25 00:40:50
就是这个
触发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。