我正在尝试连接 MS SQL 数据库,但每次尝试时都会出现此错误:
SQLException: Login failed for user ''. The user is not associated with a trusted SQL Server connection. ClientConnectionId:86b1da77-8eff-4c3f-badb-5ab75efcbab4 SQLState: S0001 VendorError: 18452
我已经在登录设置中配置了“SQL Server 身份验证”和“启用”。如果有人能解决这个问题,我将不胜感激。
这是我的代码:
public static void main(String[] args) {
String database="sisqualPONTO";
String connectionUrl = "jdbc:sqlserver://localhost:40000"+";DatabaseName=" + database+ ";integratedSecurity=true;";
String pass="****";
String user="sa";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(connectionUrl,user,pass);
System.out.println("Success");
}
catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
catch (Exception e) {
System.out.println("Error: " + e);
}
}
提前致谢。 凹凸
最佳答案
从您的连接 URL 中删除 'integratedSecurity=true'
。
关于java - SQL异常 : Login failed for user ' ' JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13381159/