my dog learned polymorphism*
The moose likes Java in General and the fly likes connect to database/ JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "connect to database/ JDBC" Watch "connect to database/ JDBC" New topic
Author

connect to database/ JDBC

Chanpreet Julka
Ranch Hand

Joined: Nov 09, 2001
Posts: 40
I am trying to connect to a sybase database using the JDBC classes, but it is telling me the driver is not found. I have been working on it and can't figure out what the problem is. Here is the code... help please. thanks.
import java.util.*;
import java.sql.*;
public class DataSheetRetriever {

public static void main(String[] args) {
Connection con = null;
String Driver = "com.sybase.jdbc2.jdbc.SybDriver";
String URL = "jdbc:sybase:Tds:";
String Host = "10.73.2.11:2010/NGSIDB";
String userid = "guest";
String passwd = "guestsun";

try {
Class.forName(Driver).newInstance();
con = DriverManager.getConnection(URL+Host, userid, passwd);
Statement select = con.createStatement();
}
catch(Exception e) {
System.err.println("Unable to load the Sybase Driver " + e.getMessage() );
if(con != null) {
try{ con.close(); }
catch(Exception ee){}

}
}
DataSheetRetriever dsr = new DataSheetRetriever();

}
public Vector getDatasheet(String siteId)
{
Vector v = new Vector();
return v;
}
}
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
hi u need to first download this 'sybase' driver and install it. then u can try running this example.
Raj
Chanpreet Julka
Ranch Hand

Joined: Nov 09, 2001
Posts: 40
thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: connect to database/ JDBC
 
Similar Threads
Hi,I have a problem in database connection
Connecting to a remote mysql database
connecting to Webtrends reporting DB using JDBC-ODBC
SQLException
Making ResultSet unEditable