|
I am following the example in Jason Hunter's
book "JAVA Servlet Programming" on page 251.
I get the following when running the servlet. I have
tried several different ways to load the Oracle Driver but failed to connect
successfully.
I suspect that I need to copy the classes111.zip, that is
currently located under the Oracle directory structure, to the PATH for
Jrun or something similar but I'm not sure.
Couldn't load database driver: oracle.jdbc.driver.OracleDriver
[oracle.jdbc.driver.OracleDriver] Thanks for any info.
Jeff
|
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class dbTest extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@atlintraweb01:1521:ntra", "system", "admin");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT NAME, ADDRESS FROM TEST");
out.println("<HTML>");
out.println("<BODY>");
out.println("<UL>");
while(rs.next()) {
out.println("<LI>" + rs.getString("name") + " " + rs.getString("address"));
}
out.println("</UL>");
out.println("</BODY>");
out.println("</HTML>");
}
catch(ClassNotFoundException e) {
out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e) {
out.println("SQLException caught: " + e.getMessage());
}
finally {
try {
if ( con != null ) con.close();
}
catch(SQLException ignored) {}
}
}
}
