使用oracle.jdbc.OracleDriver,而不是oracle.jdbc.driver.OracleDriver。如果驱动程序jar文件位于“ WEB-INF \ lib”目录中(如果使用的是Tomcat),则无需注册它。将其另存为test.jsp并将其放在您的Web目录中,然后在Tomcat管理器中重新部署您的Web应用程序文件夹:
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Simple JSP Oracle Test</TITLE>
</HEAD><BODY>
<%
Connection conn = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@XXX.XXX.XXX.XXX:XXXX:dbName", "user", "password");
Statement stmt = conn.createStatement();
out.println("Connection established!");
}
catch (Exception ex)
{
out.println("Exception: " + ex.getMessage() + "");
}
finally
{
if (conn != null) {
try {
conn.close();
}
catch (Exception ignored) {
// ignore
}
}
}
%>