How to connect Sybase database using Java code in NetBeans?

Raazan Kurunju picture Raazan Kurunju · Jul 19, 2013 · Viewed 50.3k times · Source

I want to connect remote Sybase from my Java code written in NetBeans. So far I have prepared a code as below:

public static void connect()
{
   String host = "192.168.150.11";
   String url = "jdbc:sybase:Tds:"+host+":4100";
   String username = "sa";
   String password ="";
   SybDriver sybDriver = null;
   Connection conn;

   try 
   {
      sybDriver=(SybDriver)Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
      System.out.println("Driver Loaded");
      conn = DriverManager.getConnection(url,username,password);
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("select * from zxdbl_888..account_0");
      rs.next();
      System.out.println(rs.getString(2));

   } 
   catch (InstantiationException ex) 
   {
      Logger.getLogger(Offline_charge.class.getName()).log(Level.SEVERE, null, ex);
   } 
   catch (IllegalAccessException ex) 
   {
      Logger.getLogger(Offline_charge.class.getName()).log(Level.SEVERE, null, ex);
   } 
   catch (ClassNotFoundException ex) 
   {
      Logger.getLogger(Offline_charge.class.getName()).log(Level.SEVERE, null, ex);
   } 
   catch (SQLException ex) 
   {
      Logger.getLogger(Offline_charge.class.getName()).log(Level.SEVERE, null, ex);
   }
}

and the error I got is:

java.lang.ClassNotFoundException: com.sybase.jdbc3.jdbc.SybDriver

I have loaded jconn3.jar library.

Answer

MikroDel picture MikroDel · Jul 19, 2013

Install the Sybase drivers via a Java application.

Sybase: Installing jConnect for JDBC