Ich muss eine Verbindung zu Sql Server 2008 von Java mit jdbc 4.0 herstellen. Ich habe einen sehr einfachen Code:Verbinden mit SQL-Server von Java mit JDBC (Windows-Authentifizierungsmodus)
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost;" +
"integratedSecurity=true;";
Connection con = DriverManager.getConnection(connectionUrl);
Aber ich habe diesen Fehler:
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
...
Ich folge dieser Antwort: https://stackoverflow.com/a/12524566/1554397
Ich habe jdbc4.jar in Bibliotheken/Compile
Der SQL Server-Browser-Windows-Dienst wird ausgeführt.
In SQL Server-Netzwerkkonfiguration habe ich Enebled auf TCP/IP-Eigenschaften ausgewählt.
I Set TCP-Adresse 1433.
auf Ausführen, VM-Optionen i setzen -Djava.library.path = meinen Weg und kopieren Sie in JDK, in sind sqljdbc_auth.dll sqljdbc_auth.dll.
Was soll ich tun?
EDIT: Wenn Schreib in cmd telnet localhost 1433 i get 'kann nicht geöffnet Verbindung zum Host auf Port 1433'
Sie brauchen nicht 'forName()' mit jdbc 4. –
Ok, also? Ich den gleichen Fehler ... – Blocked
No.It mit der ersten Saite gehen muss. "Verbindung mit dem Standard-Datenbank auf dem lokalen Computer mithilfe der integrierten Authentifizierung: jdbc: sqlserver: // localhost; integratedSecurity = true; " von http://msdn.microsoft.com/en-us/library/ms378428.aspx – Blocked