• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic