DATABASE: SHOWING REGISTRY

by David de Almeida Bezerra Júnior


From the MySQL Database Manager, we can generate windows for insert, update, delete and data display quickly on TetrisIDE. But, we will learn to do the manual way to pratice and rich our knowledge.

We will build a program with three windows: main window, product inserction and product query.


Creating project

Create a project named ProductRegistration and change the Title of the JFrameMain to Product.

Add two buttons and change the Title of each one to Insert and Query. Change the property Icon and select an image (your choice).



Database

On the MySQL Database Manager, in the left sidebar, insert a table named product with the columns:
id int not null primary key, description varchar(50), price decimal(9, 2)



Window Insert

Create a window, clicking with the right mouse button on Window Explorer and selecting New, with the name JDialogInsert and change the Title to Insert and Window to Dialog (Object Inspector). Add two Labels, with Text Description and Price, two TextFields, with names jTextFieldDescription and jTextFieldPrice, and a Button with Text Insert. Change the HorizontalTextAlignment of jTextFieldPrice to RIGHT and Mask to Decimal.



Select the button Insert and perform double click in the OnClick event, on Object Inspector.

Add the function insertRecord with the parameters:
product
description, price
'"+jTextFieldDescription.getText()+"', '"+jTextFieldPrice.getText()+"'

Add a function closeWindow too, without parameters.



Window Query

Create another window with name JDialogQuery and change the Title to Query and Window to Dialog (Object Inspector). Add a Table and change the name to jTableProduct. Insert the text below on properties Columns and Titles:
id
description
price



Add the function fillTable to the OnShow event of the window with the parameters:
jTableProduct
product
id, description, price
order by id

Finishing...

Go back to the JFrameMain and add the function openWindow, on button Insert, in the OnClick event with the parameter:
JDialogInsert

Add to the OnClick event of the button Query too with te parameter:
JDialogQuery

Save and Run the application, clicking on the buttons in the Toolbar ou typing CTRL + S and F9.



Click here to see the continuation.



CopyRight © 2017 Analisa Software.All Rights Reserved.