我试图通过
Java连接到SQL Server .
>我已将sqljdbc4.jar添加到我的项目库中.
>没有为访问数据库的数据库设置用户名和密码(Windows身份验证).
> 1433端口正在侦听,但我仍然收到此异常:
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ”. ClientConnectionId:085d5df3-ad69-49e1-ba32-b2b990c16a69
相关代码:
public class DataBases
{
private Connection link;
private java.sql.Statement stmt;
public ResultSet rs;
public DataBases()
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=DB;";
Connection con = DriverManager.getConnection(connectionUrl);
}
catch (SQLException e)
{
System.out.println("SQL Exception: "+ e.toString());
}
catch (ClassNotFoundException cE)
{
System.out.println("Class Not Found Exception: "+ cE.toString());
}
}
}