Java Forums › Java Forum › Java in General › help in java and sql server 2005 interfacing
help in java and sql server 2005 interfacingAll questions and answers regarding Java
| View previous topic :: View next topic |
| Author |
Message |
turkuaz07 Junior Member


Joined: Mar 14, 2009 Posts: 2
|
Posted: Wed May 27, 2009 10:35 am Post subject: help in java and sql server 2005 interfacing |
|
Hello Everyone,
I've a problem with java & SQLServer 2005 interface, i installed a SQLServer 2005 and SP2 software bundle to enable
SQLServer to run on Windows Vista, i'm using the "Windows Authentication" in SQLServer 2005 which don't need the
username or password, and i've the classpath to jar archive Microsoft JDBC-ODBC driver, i've used the following
sample code which comes with Microsoft dirver package.
import java.sql.*;
public class connectURL {
public static void main(String[] args) {
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://127.0.0.1:1433;" +
"databaseName=msdb;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 Person.Contact";
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) {}
}
}
}
When i tried to run to code above i get the following error:
"
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 127.0.0.1,
port 1433 has failed. Error: Connection refused: connect. Please verify the connection properties
and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port,
and that no firewall is blocking TCP connections to the port.
"
So, i absolutly run the SQLServer Manag. Studio, i've checked my IP address, and ports but also have the problem
could someone help me for URGENT.
Thanks in advace
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|