Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

239238Apr 30 2002
This line:

DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

causes my servlet to malfunction.

In the servlet below, the problem centers around the DriverManager line. The comments surrounding the DriverManager line describe the problem. There are no error messages; the sun version prints, the oracle version doesnt. (Ive stripped the servlet of everything except the troublesome line).

Below the servlet is a sample program provided by Oracle, run from the command line, which works perfectly: It retrieves and prints a list of names from my database.


***************************** My Servlet **************
package AgiClasses;

import javax.servlet.*;
import javax.servlet.jsp.*;
import java.util.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;

public class AgiServlet10 extends HttpServlet {

public void init(ServletConfig config) throws ServletException {
super.init(config);
}

// Process the http Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

try {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("The line before DriverManager.");

// **** Here is m problem ****

// When this line is in, it works (i.e., the "before" and "after" lines print.
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
// But when this line (below) is run in place of the one above, nothing prints.
//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

out.println("<br><br>The line after DriverManager.");

} catch(SQLException sqle) {
System.err.println("Error connecting: " + sqle);
}
}

// A post request calls the get request because they do the same thing
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
************************* End Servlet*******************************

Here is the Oracle sample program:

************************* Oracle Sample ********************

import java.sql.*;

class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

String url = "jdbc:oracle:thin:@192.168.1.4:1521:AGI";
String userName = "scott";
String password = "tiger";

Connection conn = DriverManager.getConnection (url, userName, password);

Statement stmt = conn.createStatement ();

ResultSet rset = stmt.executeQuery ("select ENAME from EMP");

while (rset.next ())
System.out.println (rset.getString (1));
}

}

******************End Sample**************************

Thanks for the help.

Logan.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2002
Added on Apr 30 2002
7 comments
2,254 views