ClassNotFoundException:JSP中的oracle.jdbc.driver.OracleDriver

时间:2014-06-10 11:23:22

标签: jsp jdbc database-connection classnotfound

我在JSP页面中遇到ClassNotFoundException:oracle.jdbc.driver.OracleDriver问题。虽然我已经在项目中添加了JAR并且能够通过另一个Java页面访问,但由于某种原因它在JSP页面中给出了异常。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"                                                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test page</title>
</head>
<body>


<form method="post">
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dao.DBConnector" %>
<table border="2">
<tr>
<td>ID</td>
<td>NAME</td>
<td>Orig Name</td>
</tr>
<%

PreparedStatement ptsmt;
ResultSet rs;
DBConnector.getConnection();
String query="select * from pseudo_customer";
try {

    Connection conn = DBConnector.sqlConnection;
    /* ptsmt = DBConnector.sqlConnection
            .prepareStatement(query); */
    ptsmt = conn.prepareStatement(query);
    rs = ptsmt.executeQuery();
    while (rs.next()) {
        %>
        <tr><td><%=rs.getInt("RECORD_ID") %></td></tr>
        <tr><td><%=rs.getString("NAME") %></td></tr>
        <tr><td><%=rs.getString("ORIG_NAME") %></td></tr>
            <%
    }
} catch (Exception ex) {
    System.out.println("Error fetching source data");
    ex.printStackTrace();
    System.exit(1);
} 

%>
    </table>
</form>
</body>
</html> 

以下是我可以访问连接的Java页面:

package com.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


public class DBConnector {

    public static Connection getNewConnection() throws Exception {
        //Class.forName("com.teradata.jdbc.TeraDriver");
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",
                "HR", "HR");

        return con;
    }



    public static Connection sqlConnection;

    public static void getConnection() {
        try {
            if (sqlConnection == null) {
                //Class.forName("com.teradata.jdbc.TeraDriver");
                Class.forName("oracle.jdbc.driver.OracleDriver");
                sqlConnection = DriverManager.getConnection(
                        "jdbc:oracle:thin:@localhost:1521:XE",
                        "HR",
                        "HR");
            }
        } catch (Exception exception) {
            System.out.println("Exception getting DB Connection");
            exception.printStackTrace();
            System.exit(1);
        }
    }
}

任何帮助将不胜感激。非常感谢。

0 个答案:

没有答案