JDBC Source

96 views
Skip to first unread message

Rage Guy

unread,
Jun 20, 2014, 10:07:41 AM6/20/14
to dataf...@googlegroups.com
I need help on this part my application process right after i load the data into my tableview

    @FXML
    private void buildData(ActionEvent event) {
        JdbcConverter<Employee> converter = new JdbcConverter<Employee>(){
            @Override
            public Employee convertOneRow(ResultSet rs) {
                Employee e = new Employee();
                try{
                    e.setFirstName(rs.getString("firstName"));
                    e.setLastName(rs.getString("lastName"));
                    e.setEmail(rs.getString("email"));
                    return e;
                }catch(SQLException ex){
                    System.out.println("Sql exception in conversion\n");
                }
                return null;
            }
        };        
        DataReader<Employee> dr = new JdbcSource("jdbc:mysql://localhost:3306/datafxcrud?user=admin&password=password",
                "select * from employee;",converter);
        
        ListDataProvider<Employee> lodp = new ListDataProvider<>(dr);        
        lodp.setResultObservableList(myList);
        lodp.retrieve();
        initializeTableView();
        System.out.println(myList.size());
    }

        
    public void initializeTableView(){
        employeeTable.setItems(myList);
        employeeTable.setEditable(true);
        firstNameColumn.setCellFactory(new PropertyValueFactory("firstName"));
        firstNameColumn.setCellFactory(new PropertyValueFactory("lastName"));
        firstNameColumn.setCellFactory(new PropertyValueFactory("email"));
        
    }


This is a snippet of the code. It seem's that i fail on retrieving data but i followed the one on the sample and i don't seem to find some errors. can someone help me?


and please guide me on where i shoulp put the code making a thread just to load the data.

Rage Guy

unread,
Jun 20, 2014, 10:55:05 AM6/20/14
to dataf...@googlegroups.com
An update this It is now working fine. but the problem is the It does not load data into my TableView it only output text in the console "regularquery" here is the update of the code.

This is the POJO
public class Employee{
    private String firstName;
    private String lastName;
    private String email;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}


And this is the controller class

        lastNameColumn.setCellFactory(new PropertyValueFactory("lastName"));
        emailColumn.setCellFactory(new PropertyValueFactory("email"));        
    }

Johan Vos

unread,
Jun 20, 2014, 11:36:56 AM6/20/14
to dataf...@googlegroups.com
What version of DataFX are you using?

Op vrijdag 20 juni 2014 16:55:05 UTC+2 schreef Rage Guy:

Rage Guy

unread,
Jun 20, 2014, 12:20:10 PM6/20/14
to dataf...@googlegroups.com
I am using 8.05b right now.
javafx8
java8
windows 7
maven at netbeans.

Rage Guy

unread,
Jun 20, 2014, 1:20:24 PM6/20/14
to dataf...@googlegroups.com
Now it's getting weirder im getting this on the stackTrace in the try-catch block at the ResultSet this is the stackTrace

java.sql.SQLException: After end of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:850)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5768)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5688)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5728)
at com.crud.datafxcrud.controller.MainWindowController$1.convertOneRow(MainWindowController.java:82)
at com.crud.datafxcrud.controller.MainWindowController$1.convertOneRow(MainWindowController.java:77)
at org.datafx.reader.converter.JdbcConverter.get(JdbcConverter.java:61)
at org.datafx.reader.JdbcSource.get(JdbcSource.java:141)
at org.datafx.provider.ListDataProvider$2.callTask(ListDataProvider.java:246)
at org.datafx.concurrent.PublishingTask.call(PublishingTask.java:57)
at org.datafx.concurrent.PublishingTask.call(PublishingTask.java:40)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1426)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at javafx.concurrent.Service$7$1.run(Service.java:744)
at javafx.concurrent.Service$7$1.run(Service.java:742)
at java.security.AccessController.doPrivileged(Native Method)
at javafx.concurrent.Service$7.run(Service.java:742)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Sql exception in conversion

Johan Vos

unread,
Jun 24, 2014, 4:53:56 AM6/24/14
to dataf...@googlegroups.com
It seems to me you're not retrieving data from your database. Can you paste the code of the MainWindowController class?

- Johan

Op vrijdag 20 juni 2014 19:20:24 UTC+2 schreef Rage Guy:
Reply all
Reply to author
Forward
0 new messages