没有通过servlet从JDBC获得输出


#code of servlet  
public class EmployeeServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String username=request.getParameter("t1");
int pass=Integer.parseInt(request.getParameter("t2"));

Connection con=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:HR/hr@localhost:1521:orclrn"+ "","system","system");
Statement stmt =con.createStatement();
String query="select * from employee where emp_id="+pass;
ResultSet rs=stmt.executeQuery(query);

while(rs.next()) {
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
}
stmt.close();
con.close();
// Redirect the response to success page

} catch (Exception e) {
e.printStackTrace();
}
}

输出:java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

异常堆栈:

. lang。ClassNotFoundException: com.mysql.jdbc.Driverorg.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java: 1407)org.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java: 1215)在java.base/. lang . class。forName0(本地方法)在java.base/java.lang.Class.forName (Class.java: 377)com.dynamic.employee.controller.EmployeeServlet.doGet (EmployeeServlet.java: 88)javax.servlet.http.HttpServlet.service (HttpServlet.java: 655)javax.servlet.http.HttpServlet.service (HttpServlet.java: 764)org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java: 227)org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java: 162)在org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java: 53)org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java: 189)org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java: 162)org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java: 197)org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java: 97)org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java: 540)org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java: 135)org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 92)org.apache.catalina.valves.AbstractAccessLogValve.invoke (AbstractAccessLogValve.java: 687)org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java: 78)org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 359)org.apache.coyote.http11.Http11Processor.service (Http11Processor.java: 399)org.apache.coyote.AbstractProcessorLight.process (AbstractProcessorLight.java: 65)org.apache.coyote.AbstractProtocol ConnectionHandler.process美元(AbstractProtocol.java: 889)org.apache.tomcat.util.net.NioEndpoint SocketProcessor.doRun美元(NioEndpoint.java: 1735)在org.apache.tomcat.util.net.SocketProcessorBase.run (SocketProcessorBase.java: 49)org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java: 1191)org.apache.tomcat.util.threads.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 659)org.apache.tomcat.util.threads.TaskThread WrappingRunnable.run美元(TaskThread.java: 61)在java.base/java.lang.Thread.run (Thread.java: 832)

getconnections()可能已经静默返回null—在这种情况下,您将不得不共享代码或自己分析。getconnections()也可能会抛出一个异常——您必须检查打印错误的stdout。

无论如何,您需要仔细检查stdout,因为您不能期望浏览器中有任何结果。如果你想要,确保写一些东西到HttpServletResponse对象-我不能在你当前的代码中看到。

编辑:

  • ClassNotFoundException表示JDBC驱动程序不在您的类路径上。不是代码本身的问题,而是检查你如何运行你的代码。

  • 您还可以检查为什么您的JDBC url包含换行符吗?

相关内容

  • 没有找到相关文章

最新更新