cancel
Showing results for 
Search instead for 
Did you mean: 

JDBC Connection Refused while using jconnect

Former Member
0 Kudos

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....

Accepted Solutions (0)

Answers (1)

Answers (1)

JasonHinsperger
Advisor
Advisor
0 Kudos

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