求大神帮忙看一下,JDBC连接SQLserver出现错误(驱动已经导入)
错误提示:java.sql.SQLException:Nosuitabledriverfoundforjdbc:microsoft:sqlserver://localho...
错误提示:java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDB62代码:package JDBC;import static org.junit.Assert.*;import java.io.InputStream;import java.sql.Connection;import java.sql.DriverManager;import java.util.Properties;import org.junit.Test;public class JDBCTest { @Test public void testDriverManager() throws Exception{ String driverClass = null; String jdbcUrl = null; String user = null; String password = null; //读取类路径下的 jdbc.properties 文件 InputStream in = getClass().getClassLoader().getResourceAsStream("jdbc.properties"); Properties properties = new Properties(); properties.load(in); driverClass = properties.getProperty("driver"); jdbcUrl = properties.getProperty("jdbcUrl"); user = properties.getProperty("user"); password = properties.getProperty("password"); //2. 加载数据库驱动程序(对应的 Driver 实现类中有注册驱动的静态代码块.) Class.forName(driverClass); //3. 通过 DriverManager 的 getConnection() 方法获取数据库连接. Connection connection = DriverManager.getConnection(jdbcUrl,user,password); System.out.println(connection); }}jdbc.properties: driver=com.microsoft.sqlserver.jdbc.SQLServerDriver jdbcUrl=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDB62 user=sa password=*****
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询