my dog learned polymorphism*
The moose likes JDBC and the fly likes jdbc driver? 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 » Databases » JDBC
Bookmark "jdbc driver?" Watch "jdbc driver?" New topic
Author

jdbc driver?

loni silverstein
Greenhorn

Joined: Jun 20, 2003
Posts: 14
I used Oracle 8.1.7 database, j2sdk1.4.1_03, and I have sequentially tested the following drivers : classes111.zip, classes12.zip, and ojdbc14.jar, but still got the same error message as it runs below. Please help!
******************************
before Unable to load driver.
--------------------------
SQLException: No suitable driver SQLState: 08001 VendorError: 0
We are in business
****************************
here is my program:
****************************

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
public
class someclass extends HttpServlet {

public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");

ServletOutputStream out = res.getOutputStream();
out.println("<html>");
out.println("<head><title>byName</title></head>");
out.println("<body>");

try {
out.println("before");
Class.forName("oracle.jdbc.driver.OracleDriver");
out.println("after");
}

catch (Exception E) {
out.println("Unable to load driver.");
E.printStackTrace();
}

out.println("<br><hr>");

try {
Connection conn = null;
conn = DriverManager.getConnection("jdbc racle:thin:@host:1521 atabase", "user", "pwd");

Statement Stmt = conn.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT * from sometable");

while (RS.next()) {
out.println(RS.getString(1));
}
// Clean up after ourselves
RS.close();
Stmt.close();
conn.close();

}
catch (SQLException E) {
out.println("SQLException: " + E.getMessage());
out.println("SQLState: " + E.getSQLState());
out.println("VendorError: " + E.getErrorCode());
}

out.println("<h1>We are in business</h1>");
out.println("</body></html>");
}

public String getServletInfo() {
return "Get infor from servlet and send it back";
}
}
[ August 08, 2003: Message edited by: long silver ]
loni silverstein
Greenhorn

Joined: Jun 20, 2003
Posts: 14
I unziped classes111.zip into the folder containing the class file, and it works. Apparently my classpath is not working.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It has nothing to do with the Classpath, it's related to two things.
Firstly, you're using the drivers in an application server (or servlet container at leats), and these ignore the classpath. It allows a single app server to serve multiple applications without having their code bases overlap.
The solution should be to place the driver JAR in the web-inf/lib directory, but since it has a .zip extension, it won't get automatically loaded. You found one solution, but another is to rename it to *.jar and drop it in the web-inf/lib directory.
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"long silver",
We require display names to be two words: your first name, a space, then your last name. Fictitious names are not allowed. You can see the rules here: http://www.javaranch.com/name.jsp
Please edit your account to show a valid display name. Otherwise your account may be deleted.
thanks,
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc driver?
 
Similar Threads
Null Pointer Exception
Data source name not found
SQLException: No suitable driver found for jdbc:mysql://localhost:3306/ SQLState: 08001 VendorError:
Connection reset by peer:JVM_recv in socket input stream read
No suitable driver problem