Home arrow Java arrow Working with DML and DDL using NetBeans IDE
JAVA

Working with DML and DDL using NetBeans IDE


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

Author Info:
By: Jagadish Chaterjee
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
June 14, 2006
TABLE OF CONTENTS:
  1. · Working with DML and DDL using NetBeans IDE
  2. · How to work with “PreparedStatement” in Java using NetBeans IDE: source code
  3. · How to work with “PreparedStatement” in Java using NetBeans IDE: explanation
  4. · How to create tables dynamically using Java with NetBeans IDE

print this article
SEARCH DEVARTICLES

Working with DML and DDL using NetBeans IDE
(Page 1 of 4 )


A downloadable file for this article is available here.

I already introduced you to NetBeans IDE in my previous article “Developing Java Applications using NetBeans.”  Even though that article is fairly introductory, the next two articles really focus on the foundation concepts you need to know about 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 work with “PreparedStatement” in Java using NetBeans IDE: creating an application

In my previous article, I gave a few examples for working with DML statements in Java.  You can consider this section an extension to that article.  In this section, we will look into “PreparedStatement” in Java.

We shall develop a small application with a button, ScrollPane and TextArea.  When the button is hit, it tries to update all the rows in the table “emp” available in the “Northwind” database.  The “Northwind” database, by default doesn’t have any “emp” table.  I just created it for simplicity, and the structure, together with the rows available in the “emp” table, would 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)  “DBSample07” in the package “MyDBPack.”

When the form (or JFrame) is created with “DBSample07,” the code behind it (only the constructor) would look something like this:

public class DBSample07 extends javax.swing.JFrame {   

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

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

public class DBSample07 extends javax.swing.JFrame {   

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

In the above code, I explicitly defined the initial size of the frame.  Before dropping all controls onto 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 Fig 1, and the “inspector” view should look something like Fig 2.


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 “PreparedStatement using Java: Demo.”

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

import java.sql.*;


blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- 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 ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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