为什么得到java.sql.SQLException:没有找到适用于jdbc:oracle:thin:@localhost:1521:xe的驱动程序。在tomcat中部署webapp时出现此错误?

时间:2018-09-10 12:50:45

标签: tomcat servlets jdbc

我将ojdbc7.jar放置在webapp lib文件夹webapp/WEB-INF/lib中,并尝试在glassfish的tomcat中进行部署。无法找到驱动程序。我正在使用以下代码,该代码遵循jdbc4.0spec对jdbc驱动程序的自动注册:

@WebServlet("/gs")
public class GetEmployeeDetailsServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();

        try {

        Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "bms", "abc");
        Statement statement = connection.createStatement();
        String sql="select * from emp_tbl";
        ResultSet resultSet = statement.executeQuery(sql);
        while(resultSet.next()){
            out.println(resultSet.getInt("eno"));
            out.println(resultSet.getString("name"));
            out.println(resultSet.getDouble("salary"));

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

    }

}

请给我一个解决方案。

0 个答案:

没有答案