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