-1

I´m developing an app using JavaFX and SQLite, it goes well but too slow, and we are starting introducing data to the database

In the operations there aren´t too mch problems, the problems became in the tables, due to the override of the ValueFactory

A solution could be to separate the tables per years or something like that, but I want to know if I´m doing right the process

Here is the overrithe of each column (replace Object by each Model), i use to have 8 colums or more than need to override the method due to are a lot of relations and Ids

idObjectEntradaColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Entrada,String>, ObservableValue<String>>() {

            @Override
            public ObservableValue<String> call(CellDataFeatures<Entrada, String> param) {
                if(null!=param.getValue().getIdObject()){

                    String nombreObject = new String();
                    ObjectGestor mObjectGestor = new ObjectGestor();
                    Object p = mObjectGestor.selectObjectFromId(param.getValue().getIdObject(),null);
                    if(null!=p.getnombreObject()){
                        nombreObject = p.getnombreObject();
                    } else {
                        nombreObject = null;

                    }

                    if (null==nombreObject){

                        return null;
                    } else {
                        ObservableValue<String> obsString = new ReadOnlyObjectWrapper<String>(nombreObject);
                        return obsString;
                    }
                } else {
                    return null;
                }
            }
        });

And the class to search in the database

Connection conn ;

    private void initConnection() {
        conn = conectarConBDSQLite(route);
    }
    public Connection conectarConBDSQLite(String ruta) {
        Connection c = null;
        
        try {
            Class.forName("org.sqlite.JDBC");
            c = DriverManager.getConnection("jdbc:sqlite:"+ruta);
        } catch ( Exception e ) {
            UtilsVictor.showAvisoScreen(e);
            return null;
        }
        //      System.out.println("Opened database successfully");
        return c;
    }
public Object selectObjectFromId(Integer id ) {
        Object object = new Object();
        try {
            initConnection();
            
            Statement stmt = conn.createStatement();
            ResultSet rs;
            rs = stmt.executeQuery("SELECT * FROM objects WHERE idObject = " + id);
            while ( rs.next() ) {
                object.setidObject(rs.getInt("idObject"));
                object.setnombreObject(rs.getString("nombreObject"));
                object.setEsDirectaObject(rs.getInt("esDirectaObject"));
                object.setTipoObject(rs.getInt("tipoObject"));
            }
            conn.close();
        } catch (Exception e) {
            
            UtilsVictor.showAvisoScreen(e);
        }
        return object;
    }

Is there any mistake?

If u need more infomation ask for it please!

Thanks in advance to all!

vLopez
  • 435
  • 5
  • 14
  • [mcve] please.. – kleopatra May 31 '22 at 09:15
  • 3
    Don’t run sql statements in the cell value factory. Fetch all the data for the table up front. Paginate with a Pagination control if needed. Use a task to fetch the data concurrently if needed. – jewelsea May 31 '22 at 09:16
  • Example [task based db access](https://gist.github.com/jewelsea/4957967). – jewelsea May 31 '22 at 09:32
  • Tutorial [sqllite and a JavaFX table](https://edencoding.com/connect-javafx-with-sqlite/). – jewelsea May 31 '22 at 09:33
  • Integrating [tables and pagination](https://stackoverflow.com/questions/15349185/javafx-tableview-paginator), also adding JDBC to that is more work. – jewelsea May 31 '22 at 09:37
  • Use a connection pooling library such as [hikari](https://www.baeldung.com/hikaricp). – jewelsea May 31 '22 at 09:38

0 Answers0