• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

no active Connection...jdbc newbie

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
Carmen


***** 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(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
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;
try{
con= this.getConnection();
if(con!=null){
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();
while(rs.next()){
System.out.println("\tcatalog: "+ rs.getString(1));
}
rs.close();
rs = null;
closeConnection();
}else System.out.println("Error: No active Connection");
}catch(Exception e){
e.printStackTrace();
}
dm=null;
}

private void closeConnection(){
try{
if(con!=null)
con.close();
con=null;
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
Connect myDbTest = new Connect();
myDbTest.displayDbProperties();
}
}

****** Connect.java End *******
[ June 01, 2006: Message edited by: Bear Bibeault ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic