Home  >  Article  >  Database  >  java.sql.SQLException: No suitable driver found for jdbc:mi

java.sql.SQLException: No suitable driver found for jdbc:mi

WBOY
WBOYOriginal
2016-06-07 15:51:432519browse

环境:SQLServer 2008 R2 MyEclipse 6.5 JDK 1.6.24 问题:Java通过JDBC连接SQLServer 2008,出现如下问题:ava.sql.SQLException: No suitable driver found forjdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=QQ。 解决:检查连接数据库时写的代

环境:SQLServer 2008 R2 + MyEclipse 6.5 + JDK 1.6.24

问题:Java通过JDBC连接SQLServer 2008,出现如下问题:ava.sql.SQLException: No suitable driver found forjdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=QQ。

 

解决:检查连接数据库时写的代码是否有问题。

代码如下:


package com.qq.client.db;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 连接数据库的类
 * @since 1.0
 * @author Wentasy
 *
 */
public class ConnDB {
	private Connection conn = null;
	
	public Connection getConn(){
		try {
			//注意这串字符串的顺序,不同的数据库版本这行不同。
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			//conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=QQ","sa","sa");
			//注:连接SQLServer 2008 没有microsoft,把这个去掉问题解决。
			conn = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;DatabaseName=QQ","sa","sa");

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return conn;
	}
}



参考资料:

http://stackoverflow.com/questions/5616898/java-sql-sqlexception-no-suitable-driver-found-for-jdbcmicrosoftsqlserver

 

附JDBC连接SQLServer 2008驱动下载,请点击这里。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn