无法通过 JDBC 查询从数据库中检索数据

Unable to retrieve data from database through JDBC query

我试图连接到我的 DDBB,以便打印 table 中的所有列,但我一直得到 Null。

我检查了连接参数,一切似乎都是正确的。

我在想我的查询语句可能有问题:

public List<Palabra> getTodos() throws SQLException {
     SQLConexion con = new SQLConexion();
     listaPalabras = new ListaPalabras();
     
     if(con.ConectarBasedeDatos()) {
         try{
             Statement stmt = con.getConnection().createStatement();  
             ResultSet rs=stmt.executeQuery("SELECT * FROM PALABRA"); 
             while(rs.next()) {
                 Palabra pal = new Palabra(rs.getInt("idPalabra"), rs.getString("palabra"), rs.getInt("dificultad")); //These are the columns that I need to print.
                 listaPalabras.addPalabra(pal); //adding the results to the list
             }
         }
         catch(Exception e)
         { 
             System.out.println(e);
         }  
     }
     else {
         return null;
     }
     
     con.DesconectarBasedeDatos();

     return listaPalabras.getListaPalabras();
 }

我设法通过将 MySQL 连接器添加到库中来解决问题,因此确实没有与数据库的连接。

新手错误。

非常感谢您的宝贵时间。