Retrieving data in a JTable
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1 • Share
Retrieving data in a JTable
A.A. Sir! kindly refer me the code to retrieve data from a SQL Server database table, in a JTable in Netbeans GUI and deleting a selected item from it. Thank you.
sharmila farooqi- Monstars
- Posts : 35
Join date : 2011-05-29
Re: Retrieving data in a JTable
Follow the given below steps to make the jatable in NetBeans , if you will face any problem at any stage let me know.
To create entity classes to represent the database that is to be bound to the JTable:
In the Projects window, right-click your project and choose New > Other, select the Persistence category, and select the Entity Classes from Database template.
In the Database Tables page of the wizard, select the database connection.
Once the Available Tables column is populated, select the tables that you want to use in your application and click Add to move them to the Selected Tables column. Click Next.
In the Entity Classes page of the wizard, make sure the Generate Named Query Annotations for Persistent Fields dialog box is selected.
Make any customizations that you want to make to the names of the generated classes and their location.
Click Create Persistence Unit.
In the Create Persistence Unit dialog box, make sure of the following things:
That the selected Persistence Library is TopLink.
That the selected Table Generation Strategy is "None".
Click Finish.
You should see nodes for the entity classes in the Projects window.
To bind the data to a JTable component:
Right-click the component in the GUI Builder and choose Bind > elements.
Click Import Data to Form. From the Import Data to Form dialog box, select the database table to which you want to bind your components. Click OK.
From the Binding Source combo box, select the item that represents the result list of the entity class. For example, if the entity class is called, Customer.java, the list object would be generated as customerList.
Leave the Binding Expression value as null.
If there are any database columns that you want to appear in the JTable, select those columns in the Selected list and move them to the Available list.
Select the Advanced tab to further configure the binding. For example, you can specify a validator or converter, or you can specify behavior if the binding source is null or unreadable.
Click OK.
To bind the data to a JList component:
Right-click the component in the GUI Builder and choose Bind > elements.
Click Import Data to Form. From the Import Data to Form dialog box, select the database table to which you want to bind your components. Click OK.
From the Binding Source combo box, select an item that represents the result list of the entity class. For example, if the entity class is called, Customer.java, the list object would be generated as customerList.
Leave the Binding Expression value as null.
In the Display Expression drop-down list, select the property that represents the database column that contains the values that you want to display in the list.
Select the Advanced tab to further configure the binding.
Click OK.
You can use the New Java Desktop Application wizard to quickly create a whole working application that has CRUD (create, read, update, and delete) features. You can also drag a database table from the Services window on to a JTable to automatically bind data to the JTable. However, it is better to generate all the entity classes in advance to ensure that all relations among the entities are correctly covered by the generated classes.
Connecting to a Database
To connect to a database you first need to do the following:
Confirm that a JDBC driver for your database is registered with the IDE.
The registered JDBC drivers are visible under the Drivers node in the Services window.
Create a database connection for the database.
A database connection is represented by a database connection node under the Databases node in the Services window.
When you create a database connection, you supply the details needed to connect to a specific database. The details needed to connect to a database include the location of the database, which driver to use and the username and password information.
After you create the database connection you can do the following:
Disconnect and reconnect to the database
Browse the database structure
View data contained in a table in the database
To create entity classes to represent the database that is to be bound to the JTable:
In the Projects window, right-click your project and choose New > Other, select the Persistence category, and select the Entity Classes from Database template.
In the Database Tables page of the wizard, select the database connection.
Once the Available Tables column is populated, select the tables that you want to use in your application and click Add to move them to the Selected Tables column. Click Next.
In the Entity Classes page of the wizard, make sure the Generate Named Query Annotations for Persistent Fields dialog box is selected.
Make any customizations that you want to make to the names of the generated classes and their location.
Click Create Persistence Unit.
In the Create Persistence Unit dialog box, make sure of the following things:
That the selected Persistence Library is TopLink.
That the selected Table Generation Strategy is "None".
Click Finish.
You should see nodes for the entity classes in the Projects window.
To bind the data to a JTable component:
Right-click the component in the GUI Builder and choose Bind > elements.
Click Import Data to Form. From the Import Data to Form dialog box, select the database table to which you want to bind your components. Click OK.
From the Binding Source combo box, select the item that represents the result list of the entity class. For example, if the entity class is called, Customer.java, the list object would be generated as customerList.
Leave the Binding Expression value as null.
If there are any database columns that you want to appear in the JTable, select those columns in the Selected list and move them to the Available list.
Select the Advanced tab to further configure the binding. For example, you can specify a validator or converter, or you can specify behavior if the binding source is null or unreadable.
Click OK.
To bind the data to a JList component:
Right-click the component in the GUI Builder and choose Bind > elements.
Click Import Data to Form. From the Import Data to Form dialog box, select the database table to which you want to bind your components. Click OK.
From the Binding Source combo box, select an item that represents the result list of the entity class. For example, if the entity class is called, Customer.java, the list object would be generated as customerList.
Leave the Binding Expression value as null.
In the Display Expression drop-down list, select the property that represents the database column that contains the values that you want to display in the list.
Select the Advanced tab to further configure the binding.
Click OK.
You can use the New Java Desktop Application wizard to quickly create a whole working application that has CRUD (create, read, update, and delete) features. You can also drag a database table from the Services window on to a JTable to automatically bind data to the JTable. However, it is better to generate all the entity classes in advance to ensure that all relations among the entities are correctly covered by the generated classes.
Connecting to a Database
To connect to a database you first need to do the following:
Confirm that a JDBC driver for your database is registered with the IDE.
The registered JDBC drivers are visible under the Drivers node in the Services window.
Create a database connection for the database.
A database connection is represented by a database connection node under the Databases node in the Services window.
When you create a database connection, you supply the details needed to connect to a specific database. The details needed to connect to a database include the location of the database, which driver to use and the username and password information.
After you create the database connection you can do the following:
Disconnect and reconnect to the database
Browse the database structure
View data contained in a table in the database
Vuhelper- Deep Bench
- Posts : 97
Join date : 2011-05-29
Similar topics
» Oil up in Asia on positive US data
» CS301- Data Structures midterm
» Google apology to New Zealanders over Wi-Fi data
» Crude down in Asia on bearish US data
» CS301- Data Structures Assignment No. 4
» CS301- Data Structures midterm
» Google apology to New Zealanders over Wi-Fi data
» Crude down in Asia on bearish US data
» CS301- Data Structures Assignment No. 4
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Today at 2:01 pm by ali001
» Goorevi App
Thu Nov 21, 2024 6:50 pm by ali001
» AMERICA EARNS! - Gift Card App
Mon Nov 18, 2024 11:07 am by ali001
» Kanba - Manage your Tasks
Thu Nov 14, 2024 12:21 pm by ali001
» Hemangiom'App
Tue Nov 05, 2024 11:25 am by ali001
» MindfulMe - Mental Health App
Mon Nov 04, 2024 10:50 am by ali001
» Learn Candlestick Patterns
Tue Oct 15, 2024 5:51 am by ali001
» Woh Pagal Si Episode 52 to 62 - Top Pakistani Drama
Sat Sep 21, 2024 6:26 pm by Mir Emmad Ali Khan Domki
» Nearu - share your socials
Sat Sep 21, 2024 1:12 pm by ali001