Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc driver?

 
loni silverstein
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I unziped classes111.zip into the folder containing the class file, and it works. Apparently my classpath is not working.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic