java连接sql server问题,求解。。
重要代码:Connection conn =null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("驱动加载成功!");
conn = DriverManager.getConnection("jdbc:mirtosoft:sqlserver://localhost:1433;DatabaseName=Myschool","sa","111111");
System.out.println("连接成功");
} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
控制台显示和报的错误:
驱动加载成功!
java.sql.SQLException: No suitable driver found for jdbc:mirtosoft:sqlserver://localhost:1433;DatabaseName=Myschool
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at 增加.Test.main(Test.java:18)
Exception in thread "main" java.lang.NullPointerException
at 增加.Test.main(Test.java:28)
[解决办法]
用的是SQLServer2005?
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=数据库名", "用户名", "密码");
你好像多了个mirtosoft
[解决办法]