问题描述
- 加载驱动成功链接失败 用户 'edu' 登录失败。
-
package testdbbase;import java.sql.*;
public class Project{
public static Connection con;
public static void main(String[] args) {
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.print("加载驱动成功");
con=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433; DatabaseName=educationi","edu","11281073");
System.out.print("链接成功");
con.close();}catch (Exception e) {
// TODO: handle exception
System.out.print("链接失败");
e.printStackTrace();}
}
}
加载驱动成功链接失败com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'edu' 登录失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2529)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at testdbbase.Project.main(Project.java:11)
解决方案
检查一下数据库登录账号、密码是否正确。