Home arrow Java arrow Page 5 - Traversing To and Fro with SQL Server Based Java Applications using NetBeans IDE
JAVA

Traversing To and Fro with SQL Server Based Java Applications using NetBeans IDE


This series introduces you to a step-by-step process for developing Java (or JFC) based applications with Microsoft SQL Server as the database, using NetBeans IDE. In this article (which is the last in this series), I shall introduce you to traversing through a set of rows more efficiently. This will be a bit different from any of the articles in this series.

Author Info:
By: Jagadish Chaterjee
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
June 28, 2006
TABLE OF CONTENTS:
  1. · Traversing To and Fro with SQL Server Based Java Applications using NetBeans IDE
  2. · How to connect to the database during form load
  3. · The Java code from IDE
  4. · The source code for buttons
  5. · How to handle the clear memory resources when the form is closed

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Traversing To and Fro with SQL Server Based Java Applications using NetBeans IDE - How to handle the clear memory resources when the form is closed
(Page 5 of 5 )

This is a special scenario we need to implement. This sort of situation never occurred in any of our previous applications. When the form was opened, we immediately started connecting to the database and retrieving information. When the form is closed, we need to close our connections and release other memory resources.

In this case, we need to trap the event of something like "window closing."  This can be achieved from the following:

  • Right click on the frame (during design time) and go to properties.

  • By default it shows "properties;" switch to "events."

  • Within the "events," select "windowClosing" and click on the "ellipsis" button.

  • Once you see the "handlers" dialog, click "Add" and give the "New Handler name" as "WhenWindowClosing."

  • Once you complete the above steps, the screen will look something like this (Fig03).

  • Once you set it up like that, click on "OK."

We need to write the following code in "Source":

private void whenWindowClosing(java.awt.event.WindowEvent evt) {                                  

// TODO add your handling code here:
         try {
            rset.close();
            sql_stmt.close();
            conn.close();
         }
         catch(Exception e) {
            this.lblMsg.setText("Error: Please view Stack
Trace");
            e.printStackTrace();
         }           

    }        

Another way to develop such applications is by using JDO (Java Data Objects). I shall cover those topics in the future. But I would like to conclude the series at this point and open a new series in the near future. 

Remarks

The entire code for this article is freely available in the form of a zip file.  That downloadable solution was developed using NetBeans 4.1 IDE and tested with Microsoft SQL Server 2000 database Enterprise Edition (with Service Pack 3) together with Microsoft Windows 2003 Standard Edition. I didn't really test it in any other version or platform.  Please follow the respective platform documentation to get it working.

The final issue you need to know is that none of my articles in this series are optimized for performance. Tuning/improving the performance of Java applications is beyond the scope of this article.  I simply wanted to explain the concepts a bit more clearly. 

Any doubts, bugs, errors, suggestions, feedback etc. are highly appreciated at jag_chat@yahoo.com.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials