(go) Java via JDBC link in MS SQL Server "no suitable driver for ..." appears

Source: Internet
Author: User

Original link: http://blog.csdn.net/stewen_001/article/details/19553173/

Front is the basic operating procedures, according to the original blogger's way to operate can ... ()

Here is a need to pay attention to the issue, but also other posts did not mention, I follow the method of the blogger modified, sure enough, no error, so, here to record

(1) We need to copy the Sqljdbc4.jar class library file to the D:\Program files\Java\jdk1.7.0\jre\lib\ext directory. (see which disk you installed, if it is C, then the first d is changed to C, the same as below)

(2) We need to copy the Sqljdbc4.jar class library file to the D:\Program Files\java\jre7\lib\ext directory

Best of all, as long as the JRE folder, copy a Sqljdbc4.jar to Jre7\lib\ext!!

(3) If you are using Tomcat as a server (I am using TOMCAT7), then we need to copy the Sqljdbc4.jar class library files to the C:\apache-tomcat-7.0.11\lib directory.

(4) If you are using Tomcat as a server, then we need to copy the Sqljdbc4.jar class library file to D:\apache-tomcat-7.0.11\webapps\gaofei\WEB-INF\ In the Lib directory (the Gaofei directory is my application, this path is believed to be understood) "Copy replication in projects in Eclipse"

Below and simple code, you can refer to

/** * @authorTwenj * @date 20170222 * @profile connect to SQL Server 2012 database*/ PackageArcgis.grid.handler;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.sql.Statement;ImportJava.util.logging.Logger; Public classConnecttosqlserver {//Connection Driver    Private Static FinalString DRIVER = "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; //Connection Path    Private Static FinalString URL = "Jdbc:sqlserver://127.0.0.1:1433;databasename=sde"; //User name    Private Static FinalString USERNAME = "sa"; //Password    Private Static FinalString PASSWORD = "0000"; //Static code block    Static {        Try{class.forname (DRIVER); } Catch(ClassNotFoundException e) {//Todo:handle ExceptionE.printstacktrace (); }    }        /*** Link Database*/     PublicConnection getconnection () {Connection conn=NULL; Try{conn=drivermanager.getconnection (URL, USERNAME, PASSWORD); } Catch(SQLException e) {//Todo:handle ExceptionE.printstacktrace (); System.out.println ("Connection Failed"); } System.out.println ("Connection succeeded"); returnConn; }        /*** Close Connection*/     Public voidClose (ResultSet rs, PreparedStatement PS, Connection conn) {if(rs! =NULL){            Try{rs.close (); RS=NULL; }Catch(SQLException e) {e.printstacktrace (); System.out.println ("Shutdown ResultSet failed"); }        }        if(PS! =NULL){            Try{ps.close (); PS=NULL; }Catch(SQLException e) {e.printstacktrace (); System.out.println ("Shutdown PreparedStatement Failed"); }        }        if(Conn! =NULL){            Try{conn.close (); Conn=NULL; }Catch(SQLException e) {e.printstacktrace (); System.out.println ("Shutdown Connection Failed"); }        }    }}

(go) Java via JDBC link in MS SQL Server "no suitable driver for ..." appears

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.