a552298242
2016-09-04 03:41
采纳率: 66.7%
浏览 2.9k
已采纳

java连接sqlserver数据库库出错,不知如何解决,求大神

我按网上给的一些解决办法尝试都没成功
TCP/IP已经启用,并且ip1和10的地址被设定为127.0.0.1,all端口设定为1433
ms-dos中输入telnet 127.0.0.1 1433,则出现了一个名为telnet 127.0.0.1 新的控制台,运行后错错误如下:另外,因为工作方面的原因最近经常要用java连接sql server,中间出现错误但是却不理解,有没有那本书是专门讲解这些错误的意义的
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。 ClientConnectionId:cd23a148-7cb6-4bc9-86de-e10675fe5d1b
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 zidingyi.GetConnectionSqlServer.getConnectionSqlServer(GetConnectionSqlServer.java:24)
at zidingyi.Try.main(Try.java:8)

我的代码如下

 public class GetConnectionSqlServer {
    public void getConnectionSqlServer() {  

        String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";  
        String dbURL = "jdbc:sqlserver://MIAO-PC\\MIAO\\\\SQLEXPRESS:1433;databasename=stmodel"; // 1433是端口,"USCSecondhandMarketDB"是数据库名称  
        String userName = "sa"; // 用户名  
        String userPwd = "sa"; // 密码  

        Connection dbConn = null;  
        try {  

            Class.forName(driverName).newInstance(); 
            System.out.println("驱动加载成功");  
        } catch (Exception ex) {  
            System.out.println("驱动加载失败");  
            ex.printStackTrace();  
        }  
        try {  
            dbConn = DriverManager.getConnection(dbURL, userName, userPwd);  
            System.out.println("成功连接数据库!");  
        } catch (Exception e) { 
            System.out.println("地址端口数据库用户名密码出错");  
            e.printStackTrace();  
        } finally {  

            try {  
                if (dbConn != null)  
                    dbConn.close();  
            } catch (SQLException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
            }  
        }  
}
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题