Java
  Home arrow Java arrow Page 5 - Traversing To and Fro with SQL Server Base...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Traversing To and Fro with SQL Server Based Java Applications using NetBeans IDE
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-06-28

    Table of Contents:
  • Traversing To and Fro with SQL Server Based Java Applications using NetBeans IDE
  • How to connect to the database during form load
  • The Java code from IDE
  • The source code for buttons
  • How to handle the clear memory resources when the form is closed

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

       · Hello guys. Another contribution on working with sql server and java. enjoy
     

    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...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT