?
Solved

having trouble with sybase connection string

Posted on 2011-05-03
36
Medium Priority
?
1,250 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:PearlJamFanatic
  • 16
  • 10
  • 6
  • +2
36 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35510554
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")

0
 
LVL 47

Accepted Solution

by:
for_yan earned 800 total points
ID: 35510566
I'm not sure what will be the name of database?
0
 
LVL 92

Expert Comment

by:objects
ID: 35510567
jdbc:sybase:Tds:<host>:<port>/<database>
pass the username and password in the call or include in the properties

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Assisted Solution

by:Jan Franek
Jan Franek earned 400 total points
ID: 35510568
If you need JDBC connection string, try this:

jdbc:sybase:Tds:oakabcd02.hld.us.abc-intl.com:4000/yourdatabase?USER=abcdefgh?PASSWORD=abcd1234

where yourdatabase is database, that you want to connect to.
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 800 total points
ID: 35510614



I guess, this is the where you can download the driver
http://www.sybase.com/detail?id=1041013&contentOnly=true
jconn2.jar in jConnect-5_5\classes

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

...

}



0
 

Author Comment

by:PearlJamFanatic
ID: 35510656
I get error
JZ003: Incorrect URL format. URL: oakabcd02.hld.us.abc-intl.com:4000:
0
 

Author Comment

by:PearlJamFanatic
ID: 35510660
i am using

      dbUrl="jdbc:sybase:Tds:" + host +
                    ":" + port + ":" + "?SERVICENAME=" + dbName;
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35510666
You don't need servicenmae just slash and then dbnmae
0
 

Author Comment

by:PearlJamFanatic
ID: 35510672
for yan : I am still getting the same error.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35510676
That's what they all show - try slash after the port and then immediately database name
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35510680
Post your code
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 35510991
>                     ":" + port + ":" + "?SERVICENAME=" + dbName;

you shouldn't have that second colon
0
 

Author Comment

by:PearlJamFanatic
ID: 35511101
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>
0
 
LVL 92

Expert Comment

by:objects
ID: 35511112
try this:

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

0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511119

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>)
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 400 total points
ID: 35511133
>>I i were to login to this databse using ASE isql then

In that case, try

jdbc:sybase:Tds:abcdefgh/dbone
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511161


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

0
 

Author Comment

by:PearlJamFanatic
ID: 35511223
new error message

Could not connect to database:
java.sql.SQLException: JZ006: Caught IOException: java.net.UnknownHostException: abcdefgh
0
 

Author Comment

by:PearlJamFanatic
ID: 35511235
for_yan: where is the Databse name in your code sample?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511236
This is better as URL  format is OK.

Probably  try host still as your  real host name
0
 
LVL 92

Expert Comment

by:objects
ID: 35511238
> 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>
0
 
LVL 92

Expert Comment

by:objects
ID: 35511242
and check what port your database is listening on (I've included the default)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511248
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?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511256
But it looks that ports may be diffeent
But you seem to know that it is 4000
0
 

Author Comment

by:PearlJamFanatic
ID: 35511264
the database server is defanately not hosted on my machine. there is some mistake in the ISE sybase logon screen
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511313
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
0
 

Author Comment

by:PearlJamFanatic
ID: 35511314
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.
0
 

Author Comment

by:PearlJamFanatic
ID: 35511330
can the moderator please edit my earlier post it needs to sensitised.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511333

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
0
 
LVL 92

Expert Comment

by:objects
ID: 35511338
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511342

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

or the same with port 2048
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511427
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35511442
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35511452
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

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35511487
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

0
 

Author Comment

by:PearlJamFanatic
ID: 35511962
This worked. I was using the wrong jar. Can you beat that?

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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question