[英]Error -java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
I want to connect to database in java web application.I wrote this code in servlet and i add related jar file(ojdbc) but when i run it,it gives me this error: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver 我想在java web应用程序中连接到数据库。我在servlet中编写了这段代码,我添加了相关的jar文件(ojdbc)但是当我运行它时,它给了我这个错误:java.lang.ClassNotFoundException:oracle.jdbc.driver。一个OracleDriver
public class DBConnection extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DBConnection() {
super();
// TODO Auto-generated constructor stub
}
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Connection con = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.101.84:1521:orcl","XXXX","XXXX");
if(con!=null)
System. out.println("Connection Successful");
else
System. out.println("error");
}
catch (Exception e) {
//System.out.println(e);
}
...
what should i do? 我该怎么办?
I was having the same issue. 我遇到了同样的问题。 What you need is to include the ojdbc6.jar file in the Deployment Assembly of the Project: 您需要的是在项目的部署程序集中包含ojdbc6.jar文件:
...and the problem is solved. ......问题解决了。
You can try this by adding your jar of oracle driver into classpath environment variable just for testing purpose. 您可以通过将jar的oracle驱动程序添加到classpath环境变量中来尝试此操作,仅用于测试目的。 or you can also load it at runtime by supplying the library into endorsed directory of your server (TOMCAT) otherwise you can copy your library file into common lib of your application server . 或者您也可以通过将库提供到服务器的endorsed目录(TOMCAT)来在运行时加载它,否则您可以将库文件复制到应用程序服务器的公共库中。 It's just related to the oracle driver library which is not loading at startup of your application.. 它只与oracle驱动程序库有关,它在应用程序启动时没有加载。
我遇到了同样的问题,但修复了它右键单击项目 - >属性并在部署程序集中添加jar(ojdbc6或14)文件然后它将工作...
I was having the same issue and what you need is 我遇到了同样的问题,你需要的是什么
You must include the ojdbc6.jar file in the Deployment Assembly of the Project....... 您必须在项目的部署程序集中包含ojdbc6.jar文件.......
1)Right click on the project 1)右键单击项目
2)select "Properties" 2)选择“属性”
3)Select "Deployment Assembly" tab 3)选择“部署程序集”选项卡
4)Add your ojdbc6.jar file in it.. 4)在其中添加你的ojdbc6.jar文件..
and the problem solve. 并解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.