Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.0 (中文) » SQL Anywhere 服务器 - 编程 » JDBC 支持 » 使用 SQL Anywhere JDBC 驱动程序

 

装载 SQL Anywhere JDBC 3.0 驱动程序

确保 SQL Anywhere JDBC 3.0 驱动程序在类文件路径下。

set classpath=install-dir\java\sajdbc.jar;%classpath%

在应用程序中使用 SQL Anywhere JDBC 3.0 驱动程序之前,必须装载相应的驱动程序。使用以下语句装载 SQL Anywhere JDBC 3.0 驱动程序:

DriverManager.registerDriver( (Driver)
    Class.forName(
    "sybase.jdbc.sqlanywhere.IDriver").newInstance()
    );

使用 newInstance 方法能解决某些浏览器中的问题。

  • 由于类是使用 Class.forName 装载的,所以不必使用 import 语句导入包含 SQL Anywhere JDBC 驱动程序的程序包。

  • 在运行应用程序时,sajdbc.jar 必须位于类文件路径中。

    set classpath=%classpath%;install-dir\java\sajdbc.jar
 所需文件