Link to home
Start Free TrialLog in
Avatar of PearlJamFanatic
PearlJamFanatic

asked on

having trouble with sybase connection string

I have the following information.

Sybase 12.5
Username: abcdefgh
Password: abcd1234
ini:
[SYB_ABCDEV]
master=NLWNSCK,oakabcd02.hld.us.abc-intl.com,4000
query=NLWNSCK,oakabcd02.hld.us.abc-intl.com,4000


What should be the connection string for the above.
Avatar of for_yan
for_yan
Flag of United States of America image

jdbc:sybase:Tds:localhost:2048/MyDatabase
com.sybase.jdbc2.jdbc.SybDriver
jconn2.jar

http://www.redmountainsw.com/wordpress/archives/jdbc-connection-urls

Perhaps this should work:

DriverManager.getConnection("jdbc:sybase:Tds:oakabcd02.hld.us.abc-intl.com:4000/NLWNSCK","abcdefgh","abcd1234")

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mick Barry
jdbc:sybase:Tds:<host>:<port>/<database>
pass the username and password in the call or include in the properties

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PearlJamFanatic
PearlJamFanatic

ASKER

I get error
JZ003: Incorrect URL format. URL: oakabcd02.hld.us.abc-intl.com:4000:
i am using

      dbUrl="jdbc:sybase:Tds:" + host +
                    ":" + port + ":" + "?SERVICENAME=" + dbName;
You don't need servicenmae just slash and then dbnmae
for yan : I am still getting the same error.
That's what they all show - try slash after the port and then immediately database name
Post your code
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I i were to login to this databse using ASE isql then

I have the following in the Sybase ASE logon screen
Login: abc
Password:xyz
Database:dbone
Server: abcdefgh
charset:
Hostname: <My machine name>
try this:

jdbc:sybase:Tds:<My machine name>:2048/dbone


Did you try this fromat:
Connection conn =
DriverManager.getConnection("jdbc:sybase:Tds:oakabcd02.hld.us.abc-intl.com:4000/dbone","abcdefgh","abcd1234");

(assuming you put the host name for <My machine name>)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial


One more simple example from

http://www.sybase.com/detail?id=1009790

The following sample code illustrates how to invoke the jConnect driver, make a connection, issue a SQL statement, and process results.



  
import java.io.*;
import java.sql.*;
 
  public class SampleCode
  {
      public static void main(String args[])
      {
          try
          {
          /*
           * Open the connection. May throw a SQLException.
           */
             Connection con = DriverManager.getConnection(
                 "jdbc:sybase:Tds:myserver:3767", "sa", "");
          /*
           * Create a statement object, the container for the SQL
           * statement. May throw a SQLException.
           */
             Statement stmt = con.createStatement();
          /*
           * Create a result set object by executing the query.
           * May throw a SQLException.
           */
             ResultSet rs = stmt.executeQuery("Select 1");
          /*
           * Process the result set.
           */

             if (rs.next())
             {
                int value = rs.getInt(1);
                System.out.println("Fetched value " + value);
             }
         }
     /*
      * Exception handling.
      */
         catch (SQLException sqe)
         {
             System.out.println("Unexpected exception : " +
                         sqe.toString() + ", sqlstate = " +
                             sqe.getSQLState());
             System.exit(1);
         }
         System.exit(0);
     }
 }
 

Open in new window

new error message

Could not connect to database:
java.sql.SQLException: JZ006: Caught IOException: java.net.UnknownHostException: abcdefgh
for_yan: where is the Databse name in your code sample?
This is better as URL  format is OK.

Probably  try host still as your  real host name
> jdbc:sybase:Tds:<My machine name>:2048/dbone

you need to put your machine name (ie. the host that the database is running on) in place of <My machine name>
and check what port your database is listening on (I've included the default)
That is good question.
I think still in all other places thety indicate slash/databasename after host name
Perhaps in thios case they have some default ofr that
But try slash/database nmae - di you try it?
But it looks that ports may be diffeent
But you seem to know that it is 4000
the database server is defanately not hosted on my machine. there is some mistake in the ISE sybase logon screen
Did you try systematically all the variants?
Your ini file should probably have correct hostname and port,
at least worth a try. Is there any place from ehrre you get this "dbone" name?
Did you try all variants of code?You showed only with "SERVICENAME",
but in the examples they have slashes in most cases
This is what i have in the ini files of the client
[SYB_CRDDEV]
master=NLWNSCK,oakautonomy02.hld.uk.fid-intl.com,4000
query=NLWNSCK,oakautonomy02.hld.uk.fid-intl.com,4000

I am able to connect and run queries using ISE.
can the moderator please edit my earlier post it needs to sensitised.

So try this:
Connection conn =
DriverManager.getConnection("jdbc:sybase:Tds:oakabcd02.hld.us.abc-intl.com:4000/db_name","abcdefgh","abcd1234");

or the same with port 2048
try this and let me know error

 jdbc:sybase:Tds:oakautonomy02.hld.uk.fid-intl.com/dbone

and also:

 jdbc:sybase:Tds:oakautonomy02.hld.uk.fid-intl.com:4000/dbone

Connection conn =
DriverManager.getConnection("jdbc:sybase:Tds:oakabcd02.hld.us.abc-intl.com:4000/dbone","abcdefgh","abcd1234");

or the same with port 2048
It looks like port numbers with Sybase are all over the place:
5000, 5010,7100, 2048,3367
And for several numbers they say those are default
And maybe 4000 is specicifc for that protocol  NLNWSCK,
so mybe with jdbc it could be different.
Try without and try several of the port numbers
this is from:
http://www.razorsql.com/docs/help_sybase.html
about Sybase port numbers:


Sybase Adaptive Server Enterprise JDBC Driver

DRIVER CLASS: com.sybase.jdbc2.jdbc.SybDriver (use jdbc3 for newer versions)

CLASS LOCATION: The Sybase installation usually includes the jConnect product. The jConnect directory structure usually contains a classes directory that houses the jconn2.jar file. This jar file can usually be used for the class location when connecting to Sybase. You may also be able to download jConnect directly from Sybase as a separate download. Consult your Sybase documentation for more information.

JDBC URL FORMAT: jdbc:sybase:Tds:<host>:<port>

There is generally no default port for Sybase, although port 7100 is used by some JDBC drivers as the default port to connect to if no port is specified for sybase. Also, port 5000 seems to sometimes be referred to as the default port for Sybase. Usually, if the default port is being used by the database server, the :<port> value of the JDBC url can be omitted.

Examples:

jdbc:sybase:Tds:neptune.acme.com:7100

jdbc:sybase:Tds:127.0.0.1:7100
Make sure you can ping oakabcd02.hld.us.abc-intl.com first. If you can't, the chances are (though not conclusive) that you won't be able to connect to it. Let me know what happens
ping oakabcd02.hld.us.abc-intl.com

Open in new window

You can follow that up with telnet. If you don't know the port, then you need to find out. Guesswork will simply waste your time, there being tens of thousands to choose from. If you can't connect with telnet, then you almost certainly won't with your Java code, and the former is faster to check.
telnet oakabcd02.hld.us.abc-intl.com 4000

Open in new window

This worked. I was using the wrong jar. Can you beat that?

      dbUrl="jdbc:sybase:Tds:" + host +
                    ":" + port+"/"+dbName;