Skip to Content
avatar image
Former Member

JDBC Connection Refused while using jconnect

import java.io.*;
import java.sql.*;
import com.sybase.jdbc4.jdbc.*;

public class JDBCConnect
{
public static void main( String args[] )
{
try
{
String arg;
Connection con;

// Select the JDBC driver and create a connection.
// May throw a SQLException.
// Choices are:
// 1. jConnect driver
// 2. SQL Anywhere JDBC 3.0 driver
// 3. SQL Anywhere JDBC 4.0 driver
arg = "jdbc4";
if( args.length > 0 ) arg = args[0];
if( arg.compareToIgnoreCase( "jconnect" ) == 0 )
{
System.out.println("jconnect started");
con = DriverManager.getConnection(
"jdbc:sybase:Tds:localhost:2638", "DBA", "sql");
}
else
{
con = DriverManager.getConnection(
"jdbc:sqlanywhere:uid=DBA;pwd=sql" );
}

System.out.println("Using "+arg+" driver");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(
"SELECT test_id, unitnm, addrm1 FROM mill");

while (rs.next())
{
int value = rs.getInt(1);
String FirstName = rs.getString(2);
String LastName = rs.getString(3);
}
rs.close();
stmt.close();
con.close();
}
catch (SQLException sqe)
{
System.out.println("Unexpected exception : " +
sqe.toString() + ", sqlstate = " +
sqe.getSQLState());
System.exit(1);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}

System.exit(0);
}
}

Works with jdbc4 Driver

==================

D:\arun\java\tesnomax>java JDBCConnect
Using jdbc4 driver
6304 null null

Failed with jConnect

==============

D:\arun\java\tesnomax>java JDBCConnect jconnect
jconnect started
Unexpected exception : java.sql.SQLException: JZ006: Caught IOException: java.ne
t.ConnectException: Connection refused: connect, sqlstate = JZ006

Any solution for this error....

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 06, 2017 at 04:57 PM

    If you are using the local engine (dbeng* ), make sure you turn on tcpip (-x tcpip), since JConnect uses tcpip to communicate with SQLA.

    --Jason

    Add comment
    10|10000 characters needed characters exceeded