• Post Reply Bookmark Topic Watch Topic
  • New Topic

no active Connection...jdbc newbie  RSS feed

Carmen Brianick
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellow ranchers, this is a pretty lengthy question (sorry!) b/c I tried to put in as much detail about my problem as I can. I am totally new to JDBC and this server stuff, so please bear with me. I am getting this error:
at com.devx.tradingapp.model.Connect.getConnection(Connect.java:27)
at com.devx.tradingapp.model.Connect.displayDbProperties(Connect.java:44)
at com.devx.tradingapp.model.Connect.main(Connect.java:80)
Error Trace in getConnection() : [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
Error: No active Connection

1.) I've created a basic class called 'Connect' (code listed below) that connects to database using jdbc
2.) I have installed SQL Server 2000 (cd is from 2001)
3.)I downloaded Microsoft SQL Server 2000 Driver for JDBC sp3 ( I also tried sp2 but still doesn't work).
4.)I have tried tips listed on "http://support.microsoft.com/default.aspx?scid=kb;en-us;313178" but it still doesn't work.
However,the only thing I didn't perform on this page was to ping my server. I'm not really sure how to perform this b/c I don't know what my server name is. I'm currently running everything on my local computer. So do they mean 'ping localhost' or 'ping local'? Currently when I open SQL Server Enterprise Manager, this is the hierarchy that I have: Console Root > Microsoft SQL Servers > (local)(Windows NT) > Now there is the Databases, Security...etc folders.
5.) I run this java application on Eclipse: Run --> Run As --> Java Application. After I run this, I get error message listed above.
6.) My OS is Windows XP

Connect.java code is below. Any instructions, comments, or sample code is greatly appreciated!

Thanks so very much for your help!

***** Connect.java Start *******
package com.devx.tradingapp.model;

import java.*;
public class Connect{
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "1433";
private final String databaseName= "Northwind";
private final String userName = "username";
private final String password = "password";
// Informs the driver to use server a side-cursor,
// which permits more than one active statement
// on a connection.
private final String selectMethod = "cursor";

// Constructor
public Connect(){}

private String getConnectionUrl(){
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";

private java.sql.Connection getConnection(){
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
System.out.println("Error Trace in getConnection() : " + e.getMessage());
return con;

Display the driver properties, database details

public void displayDbProperties(){
java.sql.DatabaseMetaData dm = null;
java.sql.ResultSet rs = null;
con= this.getConnection();
dm = con.getMetaData();
System.out.println("Driver Information");
System.out.println("\tDriver Name: "+ dm.getDriverName());
System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
System.out.println("\nDatabase Information ");
System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
System.out.println("Avalilable Catalogs ");
rs = dm.getCatalogs();
System.out.println("\tcatalog: "+ rs.getString(1));
rs = null;
}else System.out.println("Error: No active Connection");
}catch(Exception e){

private void closeConnection(){
}catch(Exception e){
public static void main(String[] args) throws Exception
Connect myDbTest = new Connect();

****** Connect.java End *******
[ June 01, 2006: Message edited by: Bear Bibeault ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!