【问题标题】:Java Jtable connect and get data from MsSql ServerJava Jtable 连接并从 MsSql Server 获取数据
【发布时间】:2014-08-12 13:09:26
【问题描述】:

我是 java swing 的新手,因为在我的项目中我无法连接并从 Microsoft sql server 获取数据到 Jtable。

但是这次我刚刚完成了它,但我仍然很感兴趣,如果我不使用代码,如果我想在没有代码的情况下使用它,我应该怎么做?在“Netbeans”中,如果单击表格内容,则可以形成导入数据。这就是我做不到的地方。

我尝试使用此按钮(将数据导入表单),但我显示了我的 sqlserver.jar,但我不能。

【问题讨论】:

    标签: java sql-server import jtable


    【解决方案1】:

    我认为这就是您想要的: http://fahdshariff.blogspot.com.br/2010/02/display-any-resultset-in-jtable.html 但是在java中,你不会没有一些代码。

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题,下面的代码可以帮助我检索所需的数据。编辑代码,使其获得您想要检索的信息。

      private class RemoveBookings implements ActionListener {
      
           String bookingID;
      
           @Override
           public void actionPerformed(ActionEvent ae) {
               if (theMainViewDisplay.bookingData.getSelectedRow() != -1) {
                   final DefaultTableModel model = (DefaultTableModel) theMainViewDisplay.bookingData.getModel();
      
                   // Get stored varible
                   int index = theMainViewDisplay.bookingData.getSelectedRow();
                   System.out.println(index);
                   theMainViewDisplay.bookingID = model.getValueAt(index, 0).toString();
                   theMainViewDisplay.pickUpLocation = model.getValueAt(index, 2).toString();
                   theMainViewDisplay.dropOffLocation = model.getValueAt(index, 3).toString();
                   System.out.println(theMainViewDisplay.bookingID);
      
                   // Remove booking from database
                   model.removeRow(theMainViewDisplay.bookingData.getSelectedRow());
                   theBackendModel.thePowList.remove(bookingID);
               }
           }
       }
      

      【讨论】:

        猜你喜欢
        • 2020-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        相关资源
        最近更新 更多