Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate How to display data from database in a TableView
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Oliver Muchai
How to display data from database in a TableView
0 Answer(s)      8 months ago
Posted in : Hibernate


I need to populate a TableView (JavaFx) with database items. I designed the TableView in JavaFx Scene Builder.

So far the TableView does not change at all and only remains blank.

This is what I have so far, but have been failing to get anything into the TableView. I will really appreciate any help; my second day now at this.

The classes:

This is the Class that creates the database data object:

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity(name = "KIWI_TABLE")
public class NewBeautifulKiwi implements Serializable {

    @Id
    @GeneratedValue
    private int KiwiId;
    private String Kiwi;

    public int getKiwiId() {
        return KiwiId;
    }

    public void setKiwiId(int KiwiId) {
        this.KiwiId = KiwiId;
    }

    public String getKiwi() {
        return Kiwi;
    }

    public void setKiwi(String Kiwi) {
        this.Kiwi = Kiwi;
    }
}

The Controller class:

import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import tableviewfix.Hibernate.HibernateTransaction;
import tableviewfix.HibernatePersist.PersistNewBeautifulKiwi;

public class FXMLDocumentController implements Initializable {

    @FXML
    private TableView<NewBeautifulKiwi> KIWI_TABLE;

    @FXML
    private TableColumn<NewBeautifulKiwi, Integer> kiwiid;

    @FXML
    private TableColumn<NewBeautifulKiwi, String> kiwi;

    public ObservableList<NewBeautifulKiwi> data;

    private List<NewBeautifulKiwi> initializeTable() {

        data = FXCollections.observableArrayList();

        HibernateTransaction hibernateTransaction = new HibernateTransaction();

        Iterator ite = hibernateTransaction.hibernateQuerry().list().iterator();
        while (ite.hasNext()) {
            NewBeautifulKiwi obj = (NewBeautifulKiwi) ite.next();

            data.add(obj);
        }



        return data;

    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        kiwiid.setCellValueFactory(new PropertyValueFactory<NewBeautifulKiwi, Integer>("kiwiid"));
        kiwi.setCellValueFactory(new PropertyValueFactory<NewBeautifulKiwi, String>("kiwi"));

        KIWI_TABLE.getItems().setAll(initializeTable());
    }   

}

The FXML file:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="293.0" prefWidth="320.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="tableviewfix.FXMLDocumentController">
  <children>
    <TableView id="showKiwiHomeTable" fx:id="KIWI_TABLE" prefHeight="293.0" prefWidth="320.0" tableMenuButtonVisible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <columns>
        <TableColumn prefWidth="75.0" text="kiwiid" fx:id="kiwiid" />
        <TableColumn prefWidth="75.0" text="kiwi" fx:id="recentKiwiShow" />
      </columns>
    </TableView>
  </children>
</AnchorPane>

The hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.h2.Driver</property>
        <property name="connection.url">jdbc:h2:file:C:/WAKILI/WAKILIdb</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.H2Dialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>




        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>

        <!-- Names the annotated entity class -->
        <mapping class="tableviewfix.NewBeautifulKiwi"/>

    </session-factory>

</hibernate-configuration>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
How to display data from database in a TableView
How to display data from database in a TableView  I need to populate a TableView (JavaFx) with database items. I designed the TableView in JavaFx... at this. The classes: This is the Class that creates the database data object: import
How to display data from database in a TableView via Hibernate
How to display data from database in a TableView via Hibernate  I need to populate a TableView (JavaFx) with database items. I designed the TableView... at this. The classes: This is the Class that creates the database data object
Advertisements
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...+",'"+email+"')"); out.println("Data is successfully inserted into database...(); in the below example. the error is "cannot convert from java.sql.Statement
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
Display Data from Database in JSP
; <html> <head> <title>display data from...;To display all the data from the table click here...</h2></TD>..., to show data from the database click on the link that calls another .jsp file named
how to display data from database according to entered value in search field
how to display data from database according to entered value in search...(); System.out.println("Disconnected from database"); } catch (Exception e...;/html> this is my searchview2.jsp file where it display the result <
how to get the data from database&how to display the database data in jsf - Java Server Faces Questions
how to get the data from database&how to display the database data in jsf  Hi, 1.how to get the data from database. 2.how to display the database... and to display the data from database in jsf visit to : http://www.roseindia.net/jsf
Display Data from Database in JSF Application
Display Data from Database in JSF Application  ... data from database in JSF application. Developing JSF  Application In this section, we are going to display data from database in JSF based web
how to display records from database
how to display records from database  I want to display records from database in tables, the database is having 2000 records and i want to display 20 records at a time and to use next and previous link buttons to show
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
Problem in populating tableview with database data using javafx MVC architecture.
Problem in populating tableview with database data using javafx MVC... architecture. Here i want to populate tableview as it is with database table data... of tableview. Controller: @FXML private void handleButtonAction(ActionEvent event
Problem in populating tableview with database data using javafx MVC architecture.
Problem in populating tableview with database data using javafx MVC... architecture. Here i want to populate tableview as it is with database table data... of tableview. Controller: @FXML private void handleButtonAction(ActionEvent event
jfreechart display from access database data.
jfreechart display from access database data.  I have made a database... to retrieve the data from the access database using prepared statement and then display... is to be done in a servlet.. Note that it is a access made database. How can I
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
How To Display both image and data into Swing JTable which is retrieved from ms access database
How To Display both image and data into Swing JTable which is retrieved from ms access database  So far this is my code how can i display both image and data from database.. while (rs.next()) { Vector row = new Vector(columns
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some.... one.jsp value of 'school' request parameter are comming from the link
display data from a table in Access Database in a HTML page
display data from a table in Access Database in a HTML page  how to display data from a table in Access Database in a HTML page in a Java Program
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
Display Data from Database in JSP
Display Data from Database in JSP   ... and execute query to display data from the specified table.  Before...;title>display data from the table using jsp</title> </head> <
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link: http://roseindia.net/jsp/servlet-jsp-data-list.shtml Thanks
display data from database in textbox when id entered in textbox
display data from database in textbox when id entered in textbox  i wanted to enter data in textbox .depending on entered data in textbox data from database should be displayed dynamically in textbox
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE  pls help me....in this i want to search books from the database... the user specified $data = mysql_query("SELECT * FROM book WHERE upper($field
Advertisements
 

 

 

DMCA.com