Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in August and this forum will be retired.

Hello, I am doing a aplication web, I have a sybase, and this DB is work, I can check my information and create queries, but when try to connect in my web, failed.

My DB is in a remote server and normally i connect with Secure shell, and in this way make a tunel, and my connection is local host, I have driver for sybase in my computer, for this reason i request your heelp.

this is my code: import java.sql.*; import java.util.Properties;

public class MyConnection {

public static void main( String[] args ) {

try {
    // *****************************************************************
    // En las siguientes líneas remueva el comentario de la línea 
    // 'Class.forName' según la versión de jConnect que vaya a usar:
    // *****************************************************************

    // Para usar jConnect 4.2:

    // Para usar jConnect 5.2:

    // Para usar jConnect 6.0:

    // *****************************************************************
    // En las siguientes líneas se definen las propiedades de la 
    // conexión. Reemplace:
    // <user>: Usuario en la base de datos
    // <passwd>: Contraseña
    // Puede incluir otras propiedades, como CHARSET, HOSTNAME, 
    // *****************************************************************
    Properties props = new Properties();
    props.put("user", "user");
    props.put("password", "pass");

    // *****************************************************************
    // En la siguiente línea se define el URL (dirección) del servidor 
    // de base de datos. Reemplace:
    // <host>: Dirección IP o nombre de la máquina donde corre la base de datos
    // <port>: Puerto del servidor de base de datos
    // *****************************************************************
    String url = "jdbc:sybase:Tds:localhost:2640";

    // *****************************************************************
    // En la siguiente línea se establece la conexión, usando la
    // dirección y propiedades previamente definidas:
    // *****************************************************************
    Connection conn = DriverManager.getConnection(url, props);

    // *****************************************************************
    // En las siguientes líneas se crea y ejecuta la sentencia SQL. La
    // ejecución crea también un conjunto resultado.
    // *****************************************************************
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery( "select 
    p.hour_id AS HORA,
    p.date_id AS FECHA,
    100*sum(p.CLSDCCH_CNDROP)/sum(p.CLSDCCH_CMSESTAB) as blocks_SDCCH


    CELL_NAME like 'ctcl%' 
    and FECHA='2013-03-22'

    group by FECHA, HORA , p.CELL_NAME
    order by p.CELL_NAME, FECHA, HORA");

    // *****************************************************************
    // En las siguientes líneas se procesa el conjunto resultado, fila
    // por fila:
    // *****************************************************************
    while ( ) ) {
        System.out.println( "p.CELL_NAME: " + rs.getString(1) + " HORA " + rs.getString(2) + " FECHA " + rs.getString(3)+ " FECHA " + rs.getString(4) );

    // *****************************************************************
    // Finalmente, se liberan los recursos y se cierra la conexión:
    // *****************************************************************
} catch ( Exception e ) {
    System.out.println( "Ocurrio un error: " );

} // main

} // MyConnection class

asked 23 Apr '13, 16:12

Axel%20Valdes's gravatar image

Axel Valdes
accept rate: 0%

edited 23 Apr '13, 17:08

First, I do not see how this question is related to web services? Your application is a Java application that is using JDBC to connect to the server listening on localhost port 2580. Please explain?

I also presume by your description that port 2580 on your localhost has been tunneled (by ssh) through to your remote host and then will connect to port on the SQL Anywhere server that is listening to .... which: is it port 2638 (for CMDSEQ connections) or port 80 or 8080 for HTTP[S] connections? Please explain exactly your configuration.

Also, please state which version of SQL Anywhere is being used and which build number.

(23 Apr '13, 16:56) Mark Culp
Replies hidden

Thanks, the port that I am using is 2640 this port is forward in SSH in this way add 12785 192.168.X.X 2640 So, in my local host listening 2640.

This connection is for CMDSEQ.

The version that I used of SQL Anywhere is jconn4.jar 12.0.1 08 Apr 2013.

And I can do it the connection with my remote dataBase using DBVisualizer, but when I am trying to connect using java code in this application fail.

(23 Apr '13, 17:33) Axel Valdes
Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 23 Apr '13, 16:12

question was seen: 3,016 times

last updated: 23 Apr '13, 17:33