Environment: SQL Server 2008 R2 + myeclipse 6.5 + JDK 1.6.24
Problem: Java connects SQL Server 2008 through JDBC, and the following problems occur: Java.sql.SQLException:No suitable driver found forjdbc:microsoft:sqlserver:// 127.0.0.1:1433;databasename=qq.
Workaround: Check to see if there is a problem with the code written while connecting to the database.
The code is as follows:
Package com.qq.client.db;
Import java.sql.Connection;
Import Java.sql.DriverManager;
/** *
Connection Database Class
* @since 1.0
* @author wentasy * * */Public
class Conndb {
private Connection conn = null;
Public Connection Getconn () {
try {
//Note The order of this string of strings, different versions of the database this line differs.
class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = Drivermanager.getconnection ("Jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=qq", "sa", "sa");
Note: Connect SQL Server 2008 without Microsoft, remove this problem.
conn = drivermanager.getconnection ("Jdbc:sqlserver://127.0.0.1:1433;databasename=qq", "sa", "sa");
} catch (Exception e) {
//Todo:handle Exception
e.printstacktrace ();
}
Return conn
}
}
Resources:
http://stackoverflow.com/questions/5616898/java-sql-sqlexception-no- Suitable-driver-found-for-jdbcmicrosoftsqlserver
Attached JDBC Connection SQL Server 2008 Drive Download: http://download.csdn.net/detail/wentasy/4331762