Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello Guys,
I am using "net.sourceforge.jtds.jdbc.Driver" for connecting sql server 2000. But returns following error.

java.sql.SQLException: Network error IOException: Connection refused: connect

I have enabled TCP/IP and set at port 1433. I also have disabled my firewall but problem is still there. I am using Netbeans ID and for it i also have included libraries and jar file(driver).

Can any body help me please?
Posted
Updated 15-Jan-11 23:57pm
v2
Comments
TweakBird 16-Jan-11 6:03am    
Edited for formatting.
R. Giskard Reventlov 16-Jan-11 6:06am    
Is the connection string correct? (I'm sure that's the first thing you checked but worth asking)

Why not use Microsoft SQL Server JDBC Driver[^] - it's a type 4 driver.

Here is a small example:
package ajaworks.msql.connectiontest;
import java.*;
public class test extends Object
{
	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= "AjaWorks.InfoPoint.Data";
    private final String userName = "Local";
    private final String password = "Local";
    
    
    // Informs the driver to use server a side-cursor, 
    // which permits more than one active statement 
    // on a connection.
    private final String selectMethod = "cursor"; 
    
    
    private String getConnectionUrl(){
         return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
    }
    
    private java.sql.Connection getConnection(){
         try{
        	 con = java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost:1433;integratedSecurity=true"); 
        	 
        	 
              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
      {
    	test myDbTest = new test();
         myDbTest.displayDbProperties();
      }

}


Regards
Espen Harlinn
 
Share this answer
 
Comments
THEASCII 16-Jan-11 6:37am    
i have try this but it also return that jre 1.6.0 not support jdbc4.or such like that! i also have update JRE but no vain.
Espen Harlinn 16-Jan-11 6:46am    
The example runs quite well on java 1.6 under windows 7 - at least it does so on my computer :)
#realJSOP 16-Jan-11 6:49am    
He's using SQL Server 2000. Until he upgrades to recent versions, I think he's gonna to be hard-pressed to find a solution.
Espen Harlinn 16-Jan-11 6:55am    
Oh, darn :)
I googled "java sql server connection refused", and this was the first link:

http://www.websina.com/bugzero/errors/sql-server-connection-error.html[^]

If that one does help, there are about 77,000 more search results to chose from.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900