Results 1 to 5 of 5
- 05-27-2009, 11:28 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 6
- Rep Power
- 0
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.SQLSer verDriver");
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
- 05-27-2009, 11:35 AM #2
Hi,
Just check whether the below link is useful for you.
SQL Server connection error: Error establishing socket, connection refusedLast edited by RamyaSivakanth; 05-27-2009 at 11:43 AM.
Ramya:cool:
- 05-27-2009, 11:41 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 6
- Rep Power
- 0
Thank you RamyaSivakanth.
I will try it...
- 05-27-2009, 01:00 PM #4
Member
- Join Date
- Nov 2008
- Posts
- 6
- Rep Power
- 0
hey RamyaSivakanth...
I couldnt understand explanations with your link.is there another solution or could u explain me what ı am gonna do step by step...
- 05-27-2009, 01:15 PM #5
Hi,
Please do the below thing listed in the document.Just put the command mentioned below in ur command prompt.
For this kind of database connection problem, there are always two distinct issues:
The SQL server itself is not running or TCP/IP is disabled. That can be confirmed by run
netstat
and see it is listed there. And then run
telnet localhost 1433
and see it can connect (or whatever port number).
Even if the server is running, a client program such like jdbc may still fail to connect to it because of a
firewall
For testing, you can turn off the XP firewall. And if you have other firewall running, check the firewall log and see any activities that might be related.Ramya:cool:
Similar Threads
-
Connect to SQL server 2005
By comp in forum JDBCReplies: 1Last Post: 03-25-2009, 11:25 PM -
hibernate support for sql-server 2005
By javadev in forum JDBCReplies: 2Last Post: 06-25-2008, 01:48 PM -
Having problem in connecting with SQL Server 2005
By rmaadil in forum JDBCReplies: 4Last Post: 05-21-2008, 06:55 AM -
Java connecting to sql server 2005
By pelegk2 in forum JDBCReplies: 0Last Post: 04-05-2008, 09:17 PM -
SQL Server 2005 Jdbc connection
By mgt83 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 07-27-2007, 04:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks