qq_35142030
2016-11-12 01:08
采纳率: 66.7%
浏览 1.5k
已采纳

想用java连一下sql server数据库出现SQLException,求助

import java.sql.*;

public class SMS {
public static void main(String args[]){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection ct=null;
ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=StudentManager", "ss","123");
System.out.println("connected");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("unconnected1");
} catch (SQLException e) {
e.printStackTrace();
System.out.println("unconnected2");
}

}

}

com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'ss' 登录失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at SMS.main(SMS.java:9)
unconnected2

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

7条回答 默认 最新

  • Royal_lr 2016-11-12 04:26
    最佳回答

    估计是远程连接没有打开吧

    评论
    解决 无用
    打赏 举报
查看更多回答(6条)