Skip to Content
0

JDBC Connection Refused while using jconnect

Mar 03, 2017 at 04:57 PM

100

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jason Hinsperger
Mar 06, 2017 at 04:57 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded