0

I have this class in my NetBeans project:

public class ConexionBD
{
   private Connection conexion;
   private Statement consulta;
   private final String ruta;
   private final String claseDriver;
   private final String driver;

   public ConexionBD(String ruta)
   {
       this.ruta = ruta;
       this.claseDriver = "org.sqlite.JDBC";
       this.driver = "jdbc:sqlite:";
   }

   public void conectar() throws SQLException, ClassNotFoundException
   {
       Class.forName(this.claseDriver);
       this.conexion = DriverManager.getConnection(this.driver + this.ruta);
       System.out.println("Opened database successfully");
       this.consulta = this.conexion.createStatement();
       System.out.println("Statement created successfully");
   }

   public ResultSet consultar(String sql) throws SQLException
   {
       ResultSet resultado = this.consulta.executeQuery(sql);
       System.out.println(this.consulta.getConnection());
       return resultado;
   }
}

And this method which use it:

    private void buildTableView()
    {
       ConexionBD c = new ConexionBD(System.getProperty("user.dir") + "bbdd");
       ObservableList<ObservableList> data FXCollections.observableArrayList();
       System.out.println(System.getProperty("user.dir") + "\\bbdd");
       try
       {
          c.conectar(); //WORKS FINE
       }
       catch(ClassNotFoundException | SQLException e)
       {
          Constantes.showAlert(AlertType.ERROR, "Error", "Error de base de datos", "Error de conexión");
       }
       try
       {
          String sql = "select name from controller";
          ResultSet rs = c.consultar(sql); //THROWS SQLException

          while(rs.next())
          {
             ObservableList<String> row = FXCollections.observableArrayList();
             row.add(rs.getString(1));
             data.add(row);
          }
          reguladores.setItems(data);
       }
       catch(SQLException e)
       {
          Constantes.showAlert(AlertType.ERROR, "Error", "Error de base de datos", "Error al obtener los datos");
       }
       try
       {
          c.cerrar();
       } 
       catch (SQLException ex)
       {
        Constantes.showAlert(AlertType.ERROR, "Error", "Error de base de datos", "Error al cerrar la conexión");
       }

The connection method seems to work fine, but when it executes the method which calls the "executeQuery(sql)" method, it throws the SQLException.

I think I configured the jdbc driver, ojdbc library and database fine, but I can't find why the method doesn't do its job. Any clue?

The stack trace:

java.sql.SQLException: no such table: controller
at org.sqlite.DB.throwex(DB.java:288)
at org.sqlite.NestedDB.prepare(NestedDB.java:115)
at org.sqlite.DB.prepare(DB.java:114)
at org.sqlite.Stmt.executeQuery(Stmt.java:89)
at app.ConexionBD.consultar(ConexionBD.java:37)
at app.controllers.InicioController.buildTableView(InicioController.java:145)

The table does exist in database

5
  • can you post the stackTrace please? Commented May 6, 2015 at 10:57
  • Sorry, this is it: java.sql.SQLException: no such table: controller at org.sqlite.DB.throwex(DB.java:288) at org.sqlite.NestedDB.prepare(NestedDB.java:115) at org.sqlite.DB.prepare(DB.java:114) at org.sqlite.Stmt.executeQuery(Stmt.java:89) at app.ConexionBD.consultar(ConexionBD.java:37) at app.controllers.InicioController.buildTableView(InicioController.java:145) The table does exist in the database Commented May 6, 2015 at 11:15
  • Well, the message is pretty clear... Are you sure there is a controller table in your DB? Commented May 6, 2015 at 11:23
  • If I open the database with sqlite3 for windows, I can access to the table and the data in it, so I assume that the table does exist in the database Commented May 6, 2015 at 11:31
  • Are you sure you are connecting to the right database then? Commented May 6, 2015 at 12:46

1 Answer 1

1

Try to fully qualify your table name like OWNER.TABLE_NAME

Make sure the account you connect with has SELECT privilege granted to it from the table owner

Those are my two obvious suggestions

Brute force is to examine all tables like so:

    DatabaseMetaData md = connection.getMetaData();
    ResultSet rs = md.getTables(null, null, "%", null);
    while (rs.next()) {
      System.out.println(rs.getString(3));
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.