com.microsoft.sqlserver.jdbc.SQLServerException: 无法打开登录所请求的数据库 "sqldb1"。登录失败。 ClientConnectionId:dacae8f0-9a97-439a-826b-b8adf529a89b
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 com.test.connectURL.main(connectURL.java:21)
这是microsoft驱动里面给的示例程序,为什么运行起来还是会出错啊,能给我讲讲么?我用的是sql server 2012。我用的eclipse已经导入了sqljdbc4.jar了。新手求助,在线等。

解决方案 »

  1.   

     String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
             "databaseName=master;user=whentao;password=17951fwt";      // Declare the JDBC objects.
          Connection con = null;
          Statement stmt = null;
          ResultSet rs = null;      try {
             // Establish the connection.
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
             con = DriverManager.getConnection(connectionUrl);         // Create and execute an SQL statement that returns some data.
             String SQL = "SELECT TOP 10 * FROM Person.Contact";
             stmt = con.createStatement();
             rs = stmt.executeQuery(SQL);
    这是连接部分的代码
      

  2.   

    这个连接部分代码,换成master之后没问题,但是这样就不行
     String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
             "databaseName=sqdb1;user=sa;password=17951fwt";
      

  3.   

    http://bbs.csdn.net/topics/390257694?page=1#post-399361586