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?
I was having the same issue. What you need is to include the ojdbc6.jar file in the Deployment Assembly of the Project:
...and the problem is solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With