Home arrow Java arrow Page 4 - Developing SQL Server based Java Apps using NetBeans IDE
JAVA

Developing SQL Server based Java Apps using NetBeans IDE


This article introduces you to developing Java (or JFC) based applications with Microsoft SQL Server as the database, using NetBeans IDE. In this first article in a series, I will show you how to establish a connection from your Java programs to a Microsoft SQL Server database using JDBC.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 27
May 24, 2006
TABLE OF CONTENTS:
  1. · Developing SQL Server based Java Apps using NetBeans IDE
  2. · What do we need to connect to Microsoft SQL Server from Java (or JDBC)?
  3. · How to configure CLASSPATH to connect to Microsoft SQL Server database
  4. · How to establish a Microsoft SQL Server database connection using JDBC
  5. · Creating a Microsoft SQL Server database connection using NetBeans IDE: Form Design
  6. · Creating a Microsoft SQL Server database connection using NetBeans IDE: the nucleus

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Developing SQL Server based Java Apps using NetBeans IDE - How to establish a Microsoft SQL Server database connection using JDBC
(Page 4 of 6 )

You can skip to the next section if you are using NetBeans IDE.  This section is only for the Java developers who don’t make use of any IDE.

Make sure that you complete all the steps in the previous section before proceeding with this section. Once you have the correct JDBC driver installed and have configured CLASSPATH (and PATH) correctly, establishing a connection from your Java programs to your SQL Server database is pretty easy.

Regardless of whether you're trying to connect to Microsoft SQL Server, Oracle, Sybase (or any other JDBC data source), establishing a connection to any RDBMS database with Java JDBC is a simple two-step process:

    1. Load the JDBC driver.
    2. Establish the connection.

Let us go through the following program to connect to Microsoft SQL Server database.

  import java.sql.*;
  class JdbcSample1 {

    public static void main (String[] args) { 
        try { 

            Class.forName("
              
com.microsoft.jdbc.sqlserver.SQLServerDriver");  
            String url = " jdbc:microsoft:sqlserver://serverjag:1433"; 
            Connection conn = DriverManager.getConnection(url,"sa","");   
        } catch (Exception e) { 
            System.err.println("Could not connect! "); 
            e.printStackTrace(); 
        } 
    } 
  } 

From the above code, the following are the only two important statements I used to connect to Microsoft SQL Server.

  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
 
String url = " jdbc:microsoft:sqlserver://serverjag:1433";
 
Connection conn = DriverManager.getConnection(url,"sa","");  

You need to modify “serverjag” with your server name, which has Microsoft SQL Server installed.  Similarly, you also need to modify the port (default Microsoft SQL Server port is 1433), user id and password to get connected successfully.


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 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials