To update a database table using java swing application.


To update a database table using java swing application.
Packages used:
1.      javax.swing.*              : Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms.
2.      java.awt.*                    : Contains all of the classes for creating user interfaces and for painting graphics and images.
3.      java.awt.event.*                      : Provides interfaces and classes for dealing with      different types of events fired by AWT components
4.      java.sql.*                                 : Provides the API for accessing and processing data stored in a data source (usually a relational database) using the Java programming language.
Classes used:
·         JFrame             : An extended version of java.awt.Frame that adds support for the JFC/Swing component architecture.
·         Container        : A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT components. Components added to a container are tracked in a list
·         JLabel  : A display area for a short text string or an image, or both
·         JButton           : An implementation of a "push" button.
·         JTextField : JTextField is a lightweight component that allows the editing of a single line of text.
·         Connection                  : A connection (session) with a specific database. SQL statements are executed and results are returned within the context of a connection. A Connection object's database is able to provide information describing its tables, its supported SQL grammar, its stored procedures, the capabilities of this connection, and so on.
·         Statement                    : The object used for executing a static SQL statement and returning the results it produces.
·         ResultSet                     : table of data representing a database result set, which is usually generated by executing a statement that queries the database.
Logical flow of the program:
·         The swing program extends JFrame class and implements ActionListener.
·         Container object containing the JButtons,JTextFields are defined.
·         Connection is established between the database and the swing program with the data source.
·         When the “update ” button is pressed the corresponding record is updated through the object of Statement class.
·         When “next” or “previous” buttons are pressed corresponding navigation is implemented.
·         Id text field in the frame is not editable.


Important notes:
·         The swing program must import the package “javax.swing.*”.
·         To stop the execution of the program on closing frame,use the method setDefaultCloseOperation(EXIT_ON_CLOSE).
·         While writing the code for JDBC-ODBC bridge enclose it in try-catch blocks.
·         For backward mavigation, object of Statement should be initialized like this
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE )

0 comments:

Copyright © 2012 OpenTechZone | Kesari Technologies |