2013-05-27 29 views
0

我試圖連接遠程桌面上的sql server 2008。我的遠程桌面IP是192.168.175.174。用戶爲User3,密碼爲user3,數據庫爲apache_camel遠程桌面SQL Server 2008連接錯誤

它給這樣 一個錯誤的任何夥伴可以幫我聯繫

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'User3'. 
at  com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196 ) 
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246) 
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917) 
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716) 
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841) 
at java.sql.DriverManager.getConnection(Unknown Source) 
at java.sql.DriverManager.getConnection(Unknown Source) 
at database.Sqlserver_connection.main(Sqlserver_connection.java:22) 

這是我的類代碼:

package database; 

import java.sql.*; 

public class Sqlserver_connection { 
    public static void main(String[] args) { 

     // Create a variable for the connection string. 
     String connectionUrl =  "jdbc:sqlserver://192.168.175.174:1433;DatabaseName=apache_camel;user=User3;password=user3"; 
     //String Connectionurl="jdbc:sqlserver://localhost:1433;DatabaseName=YourDBName;user=UserName;Password=YourPassword" 
     //"databaseName=HelloWorld;integratedSecurity=true;"; 

     // 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); 
        System.out.println(con); 
        // Create and execute an SQL statement that returns some data. 
        String SQL = "SELECT TOP 1000 [username],[password] FROM [apache_camel].[dbo].[login]"; 
        stmt = con.createStatement(); 
        rs = stmt.executeQuery(SQL); 

        // Iterate through the data in the result set and display it. 
        while (rs.next()) { 
         System.out.println(rs.getString(1) + " " + rs.getString(1)); 
        } 
      } 

     // Handle any errors that may have occurred. 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 

     finally { 
      if (rs != null) try { rs.close(); } catch(Exception e) {} 
       if (stmt != null) try { stmt.close(); } catch(Exception e) {} 
       if (con != null) try { con.close(); } catch(Exception e) {} 
     } 
    } 
} 

回答

0

好,不知道你是否「必須」使用SQLServer的驅動程序,這裏是另一個可用於連接的驅動程序(它在純Java應用程序和Android應用程序上爲我工作),http://jtds.sourceforge.net/非常易於使用,您可以通過類DriverManager提供用戶憑據 t他的靜態方法getConnection(String url,String username,String password),例如:

Connection conn = DriverManager.getConnection(「jdbc:jtds:sqlserver://192.168.3.67:1433/androiddb」,「sa」 ,「1234」);

這裏是我幾個星期前發佈的貼子,我回答自己,它具體說明如何設置與jtds的連接,是的,它是爲android,但你可以跳過特定的android步驟(它適用於MS SQL 2008年,我測試了純Java程序)。

JTDS for MS SQL in android with ADT

,希望對大家有所幫助,問候。

+0

對不起,這是一個用戶名和密碼問題我使用遠程destop id密碼它需要sql認證 –

+0

好的,無論如何,歡迎您。 – JosephChilberry