我想连接Oracle 10g Express Edition和Java,我遵循的步骤是:
使用以下文件配置我的类路径:
C:\oracle\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar
C:\Program Files\Java\jdk1.7.0_01\bin
C:\oracleexe\app\oracle\product\10.2.0\server\BIN
然后我尝试了以下程序将其与 OCI 驱动程序连接:
import java.sql.*;
public class OracleOCIConnection
{
public static void main(String args[])
{
try
{
// load oracle driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// connect using Native-API (OCI) driver
Connection con = DriverManager.getConnection("jdbc:oracle:oci8:@","hr","hr" );
System.out.println("Connected Successfully To Oracle using OCI driver");
con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
还有这个使用瘦驱动程序:
import java.sql.*;
public class OracleThinConnection
{
public static void main(String args[])
{
try
{
// load oracle driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// connect using Thin driver
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
System.out.println("Connected Successfully To Oracle");
con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
在这两种情况下,程序都会编译,但引发错误的行是:
Class.forName("oracle.jdbc.driver.OracleDriver");
有什么帮助吗?谢谢