Java. lang. ClassNotFoundException: com. microsoft. jdbc. sqlserv

Source: Internet
Author: User
SQLServer2000JDBCdriver use: com. microsoft. jdbc. sqlserver. SQLServerDriverSQLServer2005and2008JDBCdrive use: com. microsoft. sqlserver. jdbc. SQLServerDriver and URLprefix is changed from jdbc: microsoft: sqlserver: To jdbc: sqlserver:

SQL Server 2000 JDBC driver: "com. microsoft. jdbc. sqlserver. SQLServerDriver "SQL Server 2005 and 2008 JDBC drive:" com. microsoft. sqlserver. jdbc. SQLServerDriver "and the URL prefix is changed from" jdbc: microsoft: sqlserver: // "to" jdbc: sqlserver :/

SQL Server 2000 JDBC driver: "com. microsoft. jdbc. sqlserver. SQLServerDriver"

SQL Server 2005 and 2008 JDBC drive :"Com. microsoft. sqlserver. jdbc. SQLServerDriver"

In addition, the URL prefix is changed from "jdbc: microsoft: sqlserver: //""Jdbc: sqlserver ://.

From: http://blogs.msdn.com/jdbcteam/archive/2007/06/15/java-lang-classnotfoundexception-com-microsoft-jdbc-sqlserver-sqlserverdriver.aspx

The following is an example that has been encapsulated into a function:

Public static Connection linktoSQLServer () {// String connect to SQL server String strServerIPAddress = "localhost"; String strDatabaseName = "AdventureWorks"; String url = "jdbc: sqlserver: // "+ strServerIPAddress +": 1433 "+"; DatabaseName = "+ strDatabaseName; String strUserName =" sa "; String strPassword =" 123456 "; // Connection conn = null; try {// Register the driver Class. forName ("com. microsoft. sqlserver. jdbc. SQLServerDriver "). newInstance (); try {/* Get a connection to the database */conn = DriverManager. getConnection (url, strUserName, strPassword);} catch (SQLException ex) {System. out. println ("Exception One:"); ex. printStackTrace () ;}} catch (Exception ex) {System. out. println ("Exception Two:"); ex. printStackTrace ();} System. out. println ("Connected... "); return conn;} public static void SQLServer_select () {// this code just for SQL Server try {String strCmd =" SELECT * FROM Production. location "; rs = stmt.exe cuteQuery (strCmd); while (rs. next () {System. out. println ("Column 1 has value:" + rs. getString (1); System. out. println ("Column 2 has value:" + rs. getString (2); System. out. println ("Column 3 has value:" + rs. getString (3) ;}} catch (SQLException ex) {System. out. println ("SQLException:" + ex. getMessage (); System. out. println ("SQLState:" + ex. getSQLState (); System. out. println ("VendorError:" + ex. getErrorCode ());}}

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.