Java
  Home arrow Java arrow Page 4 - Developing SQL Server based Java Apps usin...
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

Developing SQL Server based Java Apps using NetBeans IDE
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2006-05-24

    Table of Contents:
  • Developing SQL Server based Java Apps using NetBeans IDE
  • What do we need to connect to Microsoft SQL Server from Java (or JDBC)?
  • How to configure CLASSPATH to connect to Microsoft SQL Server database
  • How to establish a Microsoft SQL Server database connection using JDBC
  • Creating a Microsoft SQL Server database connection using NetBeans IDE: Form Design
  • Creating a Microsoft SQL Server database connection using NetBeans IDE: the nucleus

  • 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


    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.

    More Java Articles
    More By Jagadish Chaterjee


       · Hello guys. This contribution helps you to work with SQL Server using Java...
       · Sir, your article was really helpfull. But Sir,could you please tell me how to do...
     

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


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





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