当前位置: 代码迷 >> JavaScript >> 通过NetBeans将另一个表数据插入SQL表数据
  详细解决方案

通过NetBeans将另一个表数据插入SQL表数据

热度:77   发布时间:2023-06-05 10:29:07.0

我想通过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。

  相关解决方案