Updates records from the Access/SQL table using Swing Components

Home  »  Java  »  Advance Java  »  Java Database Connectivity  »  Updates records-GUI


This example updates records into the Access table 'SchoolClasses' on the hard disk, using classes of java.sql and java.awt and more packages with Grapchical User Interface.

  •  A JDBC-ODBC bridge driver is loaded
  •  A Connection to the database is made, using getConnection method()
  •  Using the Connection object, SQL's 'update' statement is sent to the database
  •  A message is printed on the command line indicating the command was successful
  •  Minimal exception handling is done


To build these concepts and skill, a 'SchoolClasses' table will be used as a working model. This table will be created in an Access database i.e. the SchoolDemo.mdb database will hold a 'SchoolClasses' table. The structure of the table will be as described below:

Database NameSchoolDemo.mdb
Table NameSchoolClasses
Primary KeyAdmission_No


The Following block of code creates the UI described using Java Swing Components.




The Output of UpdatesRecords table is as shown below:

Diagram 22.28 The Update Record Screen for UpdatesRecords.class.



Once the UI, (as shown in diagram 22.25), has been created it is necessary to add the functionality to the UI so that it works like any standard Window's based commerical application data entry form.

Now, first of all, you will 'Search' record entering Registration No in Reg.No JTextField like '601' and then click on the 'Search' Button. If record is exist in database then it will show all records in UI fields otherwise form will show Error Message that 'Registration No. 61 is Not Exist!!!' as shown below diagram 22.26.


Diagram 22.29 Message displayed when wrong Reg.No is entered.

Diagram 22.30 Screen Ready for udpate record

Diagram 22.31 Screen asking Do you want update this record?

Diagram 22.32 Display message Record Successfully Updated

Diagram 22.33 Display Screen after successfully updated record




JDBC - Working With User Interfaces - Using Swing Compoents

Inserts records into the Access/SQL table using Swing Components
View records from the Access table/SQL using Swing JTable
Updates records into the Access/SQL table using Swing Components
Deletes records from the Access/SQL table using Swing Components






JDBC - Programming:

View records from the Access/SQL table.
Inserts records into the Access/SQL table.
Updates records into the Access/SQL table.
Deletes records from the Access/SQL table.
Drops the Access/SQL table.





No comments:

Post a Comment