Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sybase JDBC

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
I'm having troubles connecting to a sybase server. I'm using jConnect JDBC drivers by Sybase, and I'm not sure how to use them. I don't know what to set the classpath to, the driver name... Any help would be great!! Thanks
 
jdbc drivers are java classes which connect to databases on a low-level platform, and hence they must be included in classpaths / env var's as any other extra classes. The problem I've found is that when implemeting code, the "java" interpreter often won't find them. The easist way is to add the drivers to your IDE (in JBuilder go to "Configure JDK..." I think). If you arn't using an IDE, try uncompressing the driver jar file inside the folder which your code contains (by using the command "jar -xmf mydriver.java" I think) - then the interpreter should find the classes required. (In theory you shouldn't need to uncompress the jar file, but in practice I have found this can sometimes be the only way to get it to work!!).

The way that most jdbc drivers work is a two step process - first create a new instance of the driver (see below code) like you would any other new object. Then you pass the driver instance a string which makes the actual connection. The name of the driver and the connection string should come with the documentation. If you can't find the driver name, try viewing the contents of the jar file (via an IDE or the jar function - and you should find at the end of one of the sub-folders a class named "SybaseDriver" or "myDamnDriver" or something like that...

The below code works for Oracle8i/9i DBMS's - I'm sorry but have never worked with Sybase. I hope this helps matters!!

public boolean connect() {
boolean success = false;
try {
String driver = "oracle.jdbc.driver.OracleDriver";
//Create a new instance of the driver
Class.forName(driver).newInstance();
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Driver COnnection Failed : " +e.toString(), "Error", JOptionPane.WARNING_MESSAGE);
}

try {
//Using a URL, connect ot the database
String url = "jdbc:eek:racle:eek:ci8:BEN/BEN@";
conn = DriverManager.getConnection(url);
success = true;
}
catch (SQLException e) {
JOptionPane.showMessageDialog(null, "URL Resolve Failed : " +e.toString(), "Error", JOptionPane.WARNING_MESSAGE);
}
return success;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top