问题
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
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?
回答1:
I was having the same issue. What you need is to include the ojdbc6.jar file in the Deployment Assembly of the Project:
- Right click on the project
- select "Properties"
- Select "Deployment Assembly" tab
- Add your ojdbc6.jar file in it..
...and the problem is solved.
回答2:
You can try this by adding your jar of oracle driver into classpath environment variable just for testing purpose. 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 . It's just related to the oracle driver library which is not loading at startup of your application..
回答3:
I have faced the same problem but got it fixed Right click on the project->properties and add your jar(ojdbc6 or 14) file in the deployment assembly then it will work...
回答4:
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.......
1)Right click on the project
2)select "Properties"
3)Select "Deployment Assembly" tab
4)Add your ojdbc6.jar file in it..
and the problem solve.
来源:https://stackoverflow.com/questions/17803818/error-java-lang-classnotfoundexception-oracle-jdbc-driver-oracledriver