Ok, so I'm new to this, and I've been searching for two weeks trying to get an SQL resultset to print to a TableView made by JavaFX Scene Builder. I can print my resultset using System.out.println and the data is correct, but when I try put it into a List, my tableview shows one column with 0s and the other column blank. I'm trying to print the List (println), but I get the object pointer(?) and not the data, so I can't see if I'm passing from the ResultSet to the List incorrectly.
Any help would be appreciated ... I want to understand the concept, not just get an answer.
Here's my controller code:
public class TesterUIController implements Initializable {
@FXML
private TableView<dataClass> Table;
@FXML
private Button TestButton;
@FXML
private TableColumn<dataClass, Integer> colKey;
@FXML
private TableColumn<dataClass, String> colSalesNo;
public static void main (String[] args) {
System.out.println("Main has run");
}
/**
*
* @param fxmlFileLocation
* @param resources
*/
@Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
TestButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Button Pressed");
colKey.setCellValueFactory(new PropertyValueFactory<dataClass, Integer>("Key"));
colSalesNo.setCellValueFactory(new PropertyValueFactory<dataClass, String>("SalesNo"));
Table.getItems().setAll(gobbledyGook());
}
} );
}
/*
* dataClass is a (sub)class representing the data for TableView "Table"
*/
public class dataClass {
private IntegerProperty Key;
public void setKey (int value) {KeyProperty().set(value);}
public int getKey() {
return KeyProperty().get();
}
public IntegerProperty KeyProperty() {
if (Key == null) Key = new SimpleIntegerProperty(this, "Key");
return Key;
}
private StringProperty SalesNo;
public void setSalesNo(String value) {
SalesNoProperty().set(value);
}
public String getSalesNo() {
return SalesNoProperty().get();
}
public StringProperty SalesNoProperty() {
if (SalesNo == null) SalesNo = new SimpleStringProperty(this, "SalesNo");
return SalesNo;
}
}
private List<dataClass> gobbledyGook() { //ObservableList<dataClass> gobbledyGook() { // ResultSet getData() {
Connection conn;
String dbDriver;
Statement st;
ResultSet rs;// = null;
List ll = new LinkedList();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbDriver = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};"
+ "DBQ=Inventario.mdb;";
conn = DriverManager.getConnection(dbDriver, "", "");
st = conn.createStatement();
String getSalesNumber = "SELECT * FROM SalesNumber " // TOP 1 * FROM ...
+ "ORDER BY SalesNumber.Key DESC";// LIMIT 1";
rs = st.executeQuery(getSalesNumber);
while (rs.next()) {
int Key = rs.getInt(1);
double saleNo = rs.getDouble(2);
NumberFormat formatter = new DecimalFormat("###########");
String SalesNo = formatter.format(saleNo);
System.out.println(Key + ", " + SalesNo); //key + ", " + saleNo);
dataClass roww = new dataClass();
ll.add(roww);
}
}
catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(TesterUIController.class.getName()).log(Level.SEVERE, null, ex);
}
return ll;
}
}