Inserts records into the Access/SQL table using Swing Components

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


This example inserts 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 'Insert into' 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 table structure will be as follows:

Diagram 22.20 M.S Access table 'SchoolClasses'



Since the 'SchoolClasses' table has been created and populated with upto 13-14 Test records, focus now shifts to the creation of the UI in Java. The UI will be created using Java 'Swing' objects.

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




The Output of InsertsRecords table is as shown below:

Diagram 22.21 The Data Entry Screen for InsertsRecords.class.



Once the UI, (as shown in diagram 22.21), 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, you will inserts records accroding form like i inserts records as shown below diagram 22.22, First of all you will select Student Class for example '6th' Student's Name vice versa...in this form you just leave two text boxes Phone No and Mobile No because these text boxes are optional. During filling records if you insert wrong Reg.No or RollNO then this program will display waring message as shown below diagram 22.22.

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

Diagram 22.23 Screen asking Do you want save this record?

Diagram 22.23 Display message Record Successfully Inserted

Diagram 22.24 Display message Duplicate Record is Not Allowed!




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