有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java没有从表中提取数据,只将指针放入JList

我想把来自JavaDB的三列数据放到一个JList中。当我运行我的程序时,我会得到一个列表——但它们都是数据所在位置的指针!我已经尝试了好几件事,但都陷入僵局

//这是我的类中的方法

  public void getNames()     
               throws SQLException
     {

   try
   {

          // Create a Statement object for the query.
          Statement stmt =
             conn.createStatement(
                     ResultSet.TYPE_SCROLL_SENSITIVE,
                     ResultSet.CONCUR_READ_ONLY);

          System.out.println("connecting to db for getNames()"); // This is for DEBUGGING

          // Execute the query.
          ResultSet rst = stmt.executeQuery(
                           "SELECT first_name, last_Name, person_id FROM person_info ORDER BY last_name");

          // Get the number of rows
          rst.last();                 // Move to last row
          int numRows = rst.getRow(); // Get row number
          rst.first();                // Move to first row

          // Create an array for the names.
          personData =  new Object[numRows][3];


          // Store the columns in the personData array.
          for (int row = 0; row < numRows; row++)
          {
             for (int col = 0; col < 3; col++)
             {
                personData[row][col] = rst.getObject(col + 1);
             }

             // Go to the next row in the ResultSet.
             rst.next();
          }



          // Close the connection and statement objects.
          conn.close();
          stmt.close();

          System.out.println("Printing" + Arrays.deepToString(personData)); // This is for DEBUGGING
   }
   catch (SQLException ex)
      {
         System.out.println("Hell:" + ex);
      }
   }

   //This is the method to get the above data
   public Object[][] getPersonData()
   {
   System.out.println("getPersonData()" + personData); // This is for DEBUGGING
  return personData;
  }

//这就是我所说的上面的内容并构建Jlist 名单

private void buildListPanel()
   {
    try
    {
      System.out.println("Building Panel"); // This is for DEBUGGING

     // Create a panel.
     listPanel = new JPanel();

     // Add a titled border to the panel.
     listPanel.setBorder(BorderFactory.
     createTitledBorder("Select a Name"));

     // Create an AddressBookManager object.
     pbManager = new AddressBookManager();

     pbManager.getNames();



     // Get the table data.
     Object[][] data = pbManager.getPersonData();  


     System.out.println("build list panel" + Arrays.deepToString(data));    // This is for DEBUGGING

     // Create a JList object to hold the names.
     nameList = new JList<>(data);

     // Set the number of visible rows.
     nameList.setVisibleRowCount(5);

     // Put the JList object in a scroll pane.
     scrollPane = new JScrollPane(nameList);

     // Add the scroll pane to the panel.
     listPanel.add(scrollPane);
     }
  catch(SQLException ex)
    {
     // If something goes wrong with the database, 
     // display a message to the user.
     JOptionPane.showMessageDialog(null, ex.toString());
    }
     }

I cannot seem to get a pic of results to show

I have a list of names but what appears is a list of these:
       [Ljava.lang.Object;@9225652
       [Ljava.lang.Object;@654f0d9c
       [Ljava.lang.Object;@6a400542
       [Ljava.lang.Object;@658ocfdd
       [Ljava.lang.Object;@7e0b85f9

共 (0) 个答案