我想在 Java Web 应用程序中连接到数据库。我在 servlet 中编写了这段代码并添加了相关的 jar 文件(ojdbc),但是当我运行它时,它给了我这个错误:java.lang.ClassNotFoundException:oracle.jdbc.driver。甲骨文驱动程序
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);
}
...
我应该怎么办?