Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to

843859Apr 1 2008 — edited Nov 20 2014
HAI
Im imranbaseer,
hai the below is my code
im getting the following error in the following code

CODE:
import java.sql.*;

/**
* Microsoft SQL Server JDBC test program
*/
public class JJDBC {
public JJDBC() throws Exception {
// Get connection
//DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
String connectionUrl = "jdbc:sqlserver://TNQADY61\\SQLEXPRESS:1433;"
+ "databaseName=emp;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
.newInstance();
Connection connection = DriverManager.getConnection(connectionUrl,
"TNQBJ\\rajesh1s", "Pomogranate01");
if (connection != null) {
System.out.println();
System.out.println("Successfully connected");
System.out.println();
// Meta data
DatabaseMetaData meta = connection.getMetaData();
System.out.println("\nDriver Information");
System.out.println("Driver Name: " + meta.getDriverName());
System.out.println("Driver Version: " + meta.getDriverVersion());
System.out.println("\nDatabase Information ");
System.out.println("Database Name: "
+ meta.getDatabaseProductName());
System.out.println("Database Version: "
+ meta.getDatabaseProductVersion());
}
} // Test

public static void main(String args[]) throws Exception {
JJDBC test = new JJDBC();
}
}


ERROR :

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect
* at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)*
* at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)*
* at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)*
* at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)*
* at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)*
* at java.sql.DriverManager.getConnection(Unknown Source)*
* at java.sql.DriverManager.getConnection(Unknown Source)*
* at JJDBC.<init>(JJDBC.java:14)*
* at JJDBC.main(JJDBC.java:34)*
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2008
Added on Apr 1 2008
5 comments
528 views