如何在NetBeans中使用Java代码连接Sybase数据库?

我想从NetBeans编写的Java代码中连接远程Sybase.到目前为止,我已经准备了如下代码:

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);
   }
}

我得到的错误是:

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

我已经加载了jconn3.jar库.

解决方法:

通过Java应用程序安装Sybase驱动程序.

Sybase: Installing jConnect for JDBC

上一篇:java – 只在设置一些参数时,如何在JDBC中调用存储过程


下一篇:mysql – 有没有办法将应用程序上下文传递给非Sybase数据库服务器中的数据库连接(类似于Sybase中的set_appcontext)?