*
The moose likes Tomcat and the fly likes oracle.jdbc.driver.OracleDriver cannot be resolved to a type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "oracle.jdbc.driver.OracleDriver cannot be resolved to a type" Watch "oracle.jdbc.driver.OracleDriver cannot be resolved to a type" New topic
Author

oracle.jdbc.driver.OracleDriver cannot be resolved to a type

Surender Busireddy
Greenhorn

Joined: Apr 12, 2012
Posts: 1
Hi friends,

Im getting following error when I ran my jsp code in tomcat.

"oracle.jdbc.driver.OracleDriver cannot be resolved to a type"

I have added ojdbc14.jar in my lib folder. Give me some suggestions to overcome this.

This is my JSP code.

<%@page import ="java.sql.*"%>
<%!
String username;
String password;
String tableName = "BUYSM_USERS";
Connection connection;
ResultSet rs;
%>

<%
username = request.getParameter("username");
password = request.getParameter("password");

if(username!="" && password!="")
{
try{

//register Driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//get Connection
connection = DriverManager.getConnection("jdbc: oracle:thin:@url: DB","user","pwd");

String query = "Select username,password from "+tableName+" where username = ? and password = ?";

PreparedStatement stmt = connection.prepareStatement(query);
stmt.setString(1,username);
stmt.setString(2,password);
rs = stmt.executeQuery();

boolean flag = false;
while(rs.next() && !flag){

if(username.equals(rs.getString(1)) && password.equals(rs.getString(2))){
flag = true;
}
}
if(flag)
//upload page
out.println(username+","+password);
else
//same page
out.println("not found");

}catch(Exception e){

}
}
else
out.println("Enter username & password");

%>





Thanks in advance..
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

It doesn't much matter. People will come along and tell you not to do it this way.

J2EE can be employed cheap-quick-and-dirty a la Microsoft ASP, but it's not considered good practice. J2EE has the advantage that it's secure, performant, and scalable, but to obtain all those benefits, you need to adopt a more rigorous application architecture. There's no shortage of books on the subject.

A professional-grade J2EE webapp wouldn't use code snippets on a JSP, it would employ Separation of Concerns to put the logic in a separate javabean (.java) file. Likewise, it wouldn't attempt to obtain the Oracle driver directly by name. And finally, it wouldn't reference Oracle directly in the webap at all. It would use a server-defined database connection pool.

As a purely academic exercise, the Oracle driver would have to be located in the application WAR's WEB-INF/lib directory for this JSP to see it (NOT the TOMCAT/lib directory). Also, I have doubts about using "registerDriver". The old way simply used Class.forName(), and I'm pretty sure that these days, the driver jar is self-registering.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: oracle.jdbc.driver.OracleDriver cannot be resolved to a type
 
Similar Threads
Help in database connections
with out authentication it is forwading to another page
login servlet = login successful doesn't show
JavaMail Session cannot be resolved to a type
Help needed in login page