Java
  Home arrow Java arrow Page 6 - 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 
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 / 16
    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 - Creating a Microsoft SQL Server database connection using NetBeans IDE: the nucleus


    (Page 6 of 6 )

    After completing all the steps in previous section, we need to add Microsoft SQL Server related JDBC drivers to our application.  This can be achieved with the following steps:

    • Within the “Projects” view, right-click on “Libraries” and go to “Add Jar/Folder” (Fig 03).


    • Move to your JDBC driver path (in my case, it is at “C:Program FilesMicrosoft SQL Server 2000 Driver for JDBClib”), and select all of the “.jar” files available (Fig 04).


    • After selecting “.jar” files, click “open” and your “Projects” view should look something like the following (Fig 05).

    Once you complete all the above steps, you can copy the following code in to your “btnConnectActionPerformed” event:

      try {
                //Load and register SQL Server driver
                Class.forName("
                   com.microsoft.jdbc.sqlserver.SQLServerDriver");
                //Establish a connection
                Connection conn = DriverManager.getConnection("
                   jdbc:microsoft:sqlserver://serverjag:1433","sa","");
                //Create a Statement object
                Statement sql_stmt = conn.createStatement();
                //Create a ResultSet object, execute the query and return a
                // resultset
                ResultSet rset = sql_stmt.executeQuery("SELECT * FROM
    Northwind..orders ");
                int i=0;
                while (rset.next()){
                    i++;
                }
                //Close the ResultSet and Statement
                rset.close();
                sql_stmt.close();
                //Close the database connection
                conn.close();
                this.txtMsg.setText(Integer.toString(i) + " rows found");
            }
            catch(Exception e) {
                this.txtMsg.setText("Failed to connect; Please view Stack
    Trace");
                e.printStackTrace();
            }

    You can hit F5 to execute your solution and click on the button to show you the number of rows available in “Orders” table.

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







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek