Πρόβλημα στη σύνδεση MS SQL SERVER - Netbeans
Posted: Fri Mar 11, 2011 5:36 pm
Είμαι σε Netbeans και έχω τον ακόλουθο κώδικα σε Java:
Έχω εγκαταστήσει MS SQL Server, Northwind, JDBC Driver και το jarάκι σωστά αλλά μου πετάει το εξής σφάλμα όταν πάω να συνδεθώ με την Northwind:
Κλείνω το firewall αλλά πάλι τα ίδια.
Ξέρει κανείς τι φταίει;
Code: Select all
package testsql;
import java.sql.*;
public class Main {
public static void main(String[] args) {
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;database=Northwind;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);
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT TOP 10 * FROM dbo.customers";
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(4) + " " + rs.getString(6));
}
}//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) {}
}//if
}//finally
}//main
}//Main
Code: Select all
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, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."
Ξέρει κανείς τι φταίει;