Virtual Position Forum
Please register to watch content in detail
Thanks
Admin virtual position


Join the forum, it's quick and easy

Virtual Position Forum
Please register to watch content in detail
Thanks
Admin virtual position
Virtual Position Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Retrieving data in a JTable

View previous topic View next topic Go down

GMT + 3 Hours Retrieving data in a JTable

Post by sharmila farooqi Sun May 29, 2011 6:04 pm

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.
avatar
sharmila farooqi
Monstars
Monstars

Posts : 35
Join date : 2011-05-29

Back to top Go down

GMT + 3 Hours Re: Retrieving data in a JTable

Post by Vuhelper Sun May 29, 2011 6:05 pm

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
avatar
Vuhelper
Deep Bench
Deep Bench

Posts : 97
Join date : 2011-05-29

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum