SQL Server Driver for JDBC Service Pack 3 Installation test method _java

Source: Internet
Author: User
Tags microsoft sql server sql server driver pack

1. Installation: SQL Server Driver for JDBC Service Pack 3
Download install JDBC SP3

Http://www.jb51.net/softs/234108.html

Inside the installation package

Follow the prompts to install it. There are three files to use after success:
C:/Program Files/microsoft SQL Server Driver for Jdbc/lib/msbase.jar
C:/Program Files/microsoft SQL Server Driver for Jdbc/lib/msutil.jar
C:/Program Files/microsoft SQL Server Driver for Jdbc/lib/mssqlserver.jar

2. Test code

New class file Connect.java.

Package test;
Import java.*;
Import Java.sql.Driver;
   public class connect{private java.sql.Connection con = null;
   Private final String url = "jdbc:microsoft:sqlserver://";
   Private final String servername= "localhost";
   Private final String portnumber = "1433";
   Private final String databasename= "dbtest";
   Private final String userName = "sa";
   Private final String password = "123456"; Informs the driver to use Server a side-cursor,//which permits more than one active statement/on a connectio

   N. private final String SelectMethod = "cursor"; Constructor public Connect () {} private String getConnectionUrl () {return url+servername+ ":" +portnumber+;d A

   Tabasename= "+databasename+"; selectmethod= "+selectmethod+"; ";} Private Java.sql.Connection getconnection () {try{class.forname ("Com.microsoft.jdbc.sqlserver.SQLServerDriver
        ");
  con = java.sql.DriverManager.getConnection (getConnectionUrl (), Username,password);      if (con!=null) System.out.println ("Connection successful!");
        }catch (Exception e) {e.printstacktrace ();
     System.out.println ("Error Trace in Getconnection ():" + e.getmessage ());
   return con; }/* Display the driver properties, database details */public void displaydbproperties () {JAVA.SQL.D
     Atabasemetadata DM = null;
     Java.sql.ResultSet rs = null;
        try{con= this.getconnection ();
          if (con!=null) {dm = Con.getmetadata ();
          SYSTEM.OUT.PRINTLN ("Driver information");
          System.out.println ("/tdriver Name:" + dm.getdrivername ());
          System.out.println ("/tdriver Version:" + dm.getdriverversion ());
          SYSTEM.OUT.PRINTLN ("/ndatabase information");
          System.out.println ("/tdatabase Name:" + dm.getdatabaseproductname ());
          System.out.println ("/tdatabase Version:" + dm.getdatabaseproductversion ());
          System.out.println ("avalilable catalogs");rs = Dm.getcatalogs ();
          while (Rs.next ()) {System.out.println ("/tcatalog:" + rs.getstring (1));
          } rs.close ();
          rs = null;
        CloseConnection ();
     }else System.out.println ("Error:no active Connection");
     }catch (Exception e) {e.printstacktrace ();
   } dm=null;
        private void CloseConnection () {try{if (con!=null) con.close ();
     Con=null;
     }catch (Exception e) {e.printstacktrace ();
     } public static void Main (string[] args) throws Exception {Connect mydbtest = new Connect ();
    Mydbtest.displaydbproperties (); }
}

Source of code:
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;313100
------------------------------------------
Console output after success:
Connection successful!
Driver Information
Driver Name:sqlserver
Driver version:2.2.0040

Database Information
Database Name:microsoft SQL Server
Database Version:microsoft SQL Server 2000-8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (build 3790:)

Avalilable Catalogs
Catalog:dbtest
...........


3. Question:
In the test console old output the following error!
Look for the information for a long time. It says that the path to the three jar files after the JDBC installation is in the environment variable. But I tried!
Java.lang.ClassNotFoundException:com.microsoft.jdbc.sqlserver.SQLServerDriver
.........
Error Trace in Getconnection (): Com.microsoft.jdbc.sqlserver.SQLServerDriver
Error:no Active Connection

Ask someone else to find a way:

Package Explorer--> Package name right-click Build path--> Configuration Build path-->java build path--> library--> add external jar
It's OK to choose the three jars.

The following three JDBC files are added.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.