0

I am trying to show my database data into TableView. I have a database named info and there is two columns 'fname' and 'lname' into the table 'data'. I am trying to show the data into tableview format. I've tried the following code-

package imran.jfx.application;

import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;

public class Controller implements Initializable {

    @FXML
    private TableView<?> dataView;

    @FXML
    private TableColumn<?, ?> english;

    @FXML
    private TableColumn<?, ?> bangla;

    @FXML
    private Button getData;

    ResultSet result;
    PreparedStatement doQuery;
    Connection conn;
    String query;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        try {
            Class.forName("org.sqlite.JDBC");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:sqlite::resource:database/info.db";
        try {
            conn = DriverManager.getConnection(url);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @FXML
    void showData(ActionEvent event) throws SQLException {
        query="select fname,lname from data";

        ResultSet result = conn.createStatement().executeQuery(query);

        while (result.next()) 
        {                    
            //Can't understand how should I write here to show the data
        }
    }
}

How should I do it?

Abdullah Al Imran
  • 1,166
  • 2
  • 17
  • 30
  • 1
    I've looked these type of posts before..but those doesn't solve my problem. I need specific solution in my case. My database contains unicode information. I need to know if I have a ResultSet then how do I fetch data from the ResultSet and present them into TableView. :( – Abdullah Al Imran Sep 26 '15 at 20:19
  • Unfortunately, we have a lot of crap to close and a lot of robo-closers on rampage. The balance between them is a little bit buggy... :-( Sincere condolences. I vote to reopen it, but it will be probably not enough. Anyways, it helps a lot if you detail, why the other question isn't a duplicate. Write it into the top of your question, as "edit". – peterh Sep 26 '15 at 21:38
  • Sorry, I see nothing at all different in your question to the one linked, even after reading your comment. Have you tried to implement it that way? If there is some reason that approach will not work, you need to edit your question and carefully explain why your situation is different. – James_D Sep 26 '15 at 23:45
  • @peterh what is the basis for reopening? I see no evidence that this is different to the linked question. – James_D Sep 26 '15 at 23:46
  • @James_D 1) the "duplicate" you linked to, is a crap. 2) it wants example code sample, which is at least low-level, but probably even offtopic here. 3) it wants debug of an existing code, while the duplicate wants a code snippet. – peterh Sep 27 '15 at 13:22
  • @James_D To me, 1) is the most important. *Don't link to crap.* – peterh Sep 27 '15 at 13:23
  • I agree that the linked question is poor, and potentially off-topic. However this question is no better: it is not asking to debug existing code, it is just providing some minimal (and pretty much incidental) background and then saying "I have no idea how to do xxx, can you do it for me". So if the linked question is off-topic, so is this one. Any answer to this question would be basically identical to the answer to the question I linked (which has actually been used as a duplicate for several questions under this tag, so it's quite useful from that perspective). – James_D Sep 27 '15 at 14:29

0 Answers0