Java
  Home arrow Java arrow Working with DML to Develop SQL Server bas...
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

Working with DML to Develop 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 / 4
    2006-06-07

    Table of Contents:
  • Working with DML to Develop SQL Server based Java Applications using NetBeans IDE
  • How to write the output of a SELECT statement to a text file using Java with NetBeans IDE: source code
  • How to write the output of a SELECT statement to a text file using Java with NetBeans IDE: explanation
  • How to INSERT, UPDATE or DELETE rows using Java

  • 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


    Working with DML to Develop SQL Server based Java Applications using NetBeans IDE


    (Page 1 of 4 )

    This article introduces you to a step-by-step process for developing Java (or JFC) based applications with Microsoft SQL Server as database, using NetBeans IDE. The third in a series, this article introduces you to working with DML statements such as SELECT, INSERT, UPDATE and DELETE.
    A downloadable file for this article is available here.

    I already introduced about NetBeans IDE in my previous article "Developing Java Applications using NetBeans."  Even though, that article is fairly an introductory article, the next two articles are concentrated on basics of JFC.  You can find the next two articles here and here

    If you are new to NetBeans IDE, I strongly suggest you go through the existing articles first, before proceeding with this one.  If you are new to developing Microsoft SQL Server based Java applications, I request you go through another article of mine here.

    How to write the output of a SELECT statement to a text file using Java with NetBeans IDE: creating the application

    We shall develop a small application with a button, ScrollPane and TextArea.  When the button is hit, it needs to write out all the rows given by the SELECT statement to a text file.  For the purpose of this series, I created a simple table named "emp" in the "Northwind" database of SQL Server 2000.  The structure and rows available in the "emp" table will be as follows:

    Empno    Ename          Sal           Deptno  

    -------- -------------- ------------- ------

    1001     Jag            4200.0        10

    1002     Chat           5000.0        20

    1003     Win            3500.0        10

    1004     Dhan           4600.0        20

    Currently, I named the project "SampleJavaApplication1" and the form (or JFrame) "DBSample03" in the package "MyDBPack."

    When the form (or JFrame) is created with "DBSample03," the code behind it (only the constructor) would look something like the following:

    public class DBSample03 extends javax.swing.JFrame {   

        /** Creates new form DBSample03 */
        public DBSample03() {
            initComponents();
        }

    Make changes to the above code fragment in such a way that it looks similar to the following:

    public class DBSample03 extends javax.swing.JFrame {   

        /** Creates new form DBSample03 */
        public DBSample03() {
            initComponents();
            this.setSize(300,200);
        }

    In the above code, I explicitly defined the initial size of the frame.  Before dropping all the controls on the form, set the layout to "null layout" (fig 01) to ease our development for this article.  When you complete your form design, it should look something like the first figure below, and the "inspector" view should look something like the second one.


    Fig 1


    Fig 2

    For the convenience of writing understandable code, I named those controls as follows:

    btnConnect
    jScrollPane1
    txtMsg

    I also gave a value to the Frame property "title" (using the property window), namely "Writing SELECT output to file using Java: Demo."

    You are also required to import the necessary packages as shown below:

    import java.sql.*;
    import java.util.*;
    import java.io.*;

    "java.io" is necessary to work with "streams" in java.

    More Java Articles
    More By Jagadish Chaterjee


       · Hello guys! this is another extension to my previous contribution on sql server with...
     

    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 2 hosted by Hostway
    Stay green...Green IT