|
可能是驱动包配置的问题 求大神指点
下边是代码
package pkg;
import java.sql.*;
public class Main {
public static void main(String[] args) {
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=SQLEXPRESS";
String userName="sa";
String userPwd="zsmj1992";
try {
Class.forName(driverName);
Connection con=DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("连接数据库成功!");
}
catch (ClassNotFoundException e) {
//TODO Auto-generated catch block
e.printStackTrace();
System.out.println("连接数据库失败!1111");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("连接数据库失败!2222");
}
}
下边是运行的结果:
sqlserver.jdbc.SQLServerException: 无法打开登录所请求的数据库 "SQLEXPRESS"。登录失败。 ClientConnectionId:6290345a-e4aa-450c-888e-fa1e87dc0a5e连接数据库失败!2222
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at pkg.Main.main(Main.java:14)
这是我的驱动包路径 E:\数据库\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\chs 里面有sqljdbc4.jar 和 sqljdbc.jar
我把sqljdbc4.jar复制到了这个目录下F:\Program Files\JRE\lib\ext
path 也设置了%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;E:\数据库\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\chs\sqljdbc4.jar
请问哪里出了问题
初学者求大神指点
|
|