SQLException:缺少servlet中的定义

时间:2013-12-26 05:15:25

标签: servlets sqlexception

我正在使用oracle.jdbc.OracleDriver使用jsp和servlet编写一个Web应用程序。这个代码在我的电脑上工作正常,但是当试图在其他服务器上部署应用程序的构建时,我得到这样的Exception。

java.sql.SQLException: Missing defines
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:158)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:305)
at oracle.jdbc.driver.OracleStatement.prepareAccessors(OracleStatement.java:793)
at oracle.jdbc.driver.T4CResultSetAccessor.getCursor(T4CResultSetAccessor.java:235)
at oracle.jdbc.driver.ResultSetAccessor.getObject(ResultSetAccessor.java:95)
at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:1947)
at org.apache.tomcat.dbcp.dbcp.DelegatingCallableStatement.getObject(DelegatingCallableStatement.java:143)
at cwep.Login.processRequest(Login.java:127)
at cwep.Login.doPost(Login.java:198)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
at java.lang.Thread.run(Unknown Source)

调试我的应用程序后,我发现当我在服务器端调用数据库(Oracle 10g)程序并使用callableStatement.registerOutParameter(1,OracleTypes.CURSOR)获取游标时,我在上面看到了异常     callableStatement.execute();声明。

protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
static String CNPOOL = "cnpool";//Getting CNPOOL correctly for database connection
 CallableStatement cs = null;
 static DataSource dataSource;//Declared as global
        response.setContentType("text/html;charset=UTF-8");

            PrintWriter out = response.getWriter();
            CallableStatement cs = null;
            String str = conectionPool;
            System.out.println(str);
            try {
            InitialContext initContext = new InitialContext();
            Context context = (Context) initContext.lookup("java:/comp/env");
            dataSource = (DataSource) context.lookup(str);
            System.out.println(" CxN Pool " + str);
            String username = request.getParameter("username");
            String password = request.getParameter("password");
            ecode = Integer.parseInt(username);
            System.out.println(" eCode " + ecode);
            try {
                con = ConnectionBean.getConnection(dataSource);
                System.out.println(" CxN " + con.toString());
            } catch (Exception e) {
                System.out.println(" Opening the Cxn 1st Time" + e);
            }
            if(con!=null)
            {
            System.out.println(" Before Calling proc_user_login " + ecode);
            cs = con.prepareCall("{call proc_user_login(?,?,?,?,?)}");
            cs.setInt(1, empcode);
            cs.setString(2, password);
            cs.registerOutParameter(3, Types.NUMERIC);
            cs.registerOutParameter(4, Types.NUMERIC);
            cs.registerOutParameter(5, Types.VARCHAR);
            try {
                cs.execute();
            } catch (Exception e) {
                System.out.println("--------------------After executing first proc----------------------- ");
            }
            int message = cs.getInt(3);

            if (message == 0) {

                cs = con.prepareCall("{call proc_get_XXXlist(?,?)}");
                cs.setInt(1, empcode);
                cs.registerOutParameter(2, OracleTypes.CURSOR);
                try {
                     System.out.println("Before executing XXXList proc ");
                    cs.execute();      //GETTING EXCEPTION AT THIS STATEMENT
                    System.out.println("After executing XXXList");
                } catch (Exception e) {
                    System.out.println("exception in After executing secod proc ");
                }
                ResultSet rset = (ResultSet) cs.getObject(2);
                Vector v1 = new Vector();
                Vector v2 = new Vector();
                Vector v3 = new Vector();
                while (rset.next()) {       
                    v1.addElement(rset.getString(1));
                    v2.addElement(rset.getString(2));
                    v3.addElement(rset.getString(3));
                }
                //rset.last();
                String[] str1 = new String[v1.size()];
                String[] str2 = new String[v2.size()];
                String[] str3 = new String[v3.size()];
                v1.copyInto(str1);
                v2.copyInto(str2);
                v3.copyInto(str3);

                request.setAttribute("ecode", Integer.toString(ecode));
                request.setAttribute("clientid", str1);
                request.setAttribute("constring", str2);
                request.setAttribute("URL", str3);
                RequestDispatcher rd = request.getRequestDispatcher("XXX.jsp");

                rd.forward(request, response);
                //response.sendRedirect("XXX.jsp");
            } else {
                response.sendRedirect("index.jsp?val=" + message);
            }

            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("EEE---" + e);
            Utility.log("FinalExceptionToServlet.namelookup:", e.toString(), "SERVER", "E");
        }
    }

在这段代码中,第一个数据库的login_usr程序执行正常,但是当试图执行第二个程序时,它返回一个游标作为outparameter,我得到了异常。如果同样的代码在我的电脑上工作正常,那么它为什么抛出异常在Serverside部署后尝试执行callablestatement时。我正在使用Ojdbc14.jar和classes12.jar.Is有任何.jar错配.. ???

提前致谢。

1 个答案:

答案 0 :(得分:0)

正如您所提到的那样,代码运行得更早,罪魁祸首可能是OracleTypes。作为它的抽象类,你需要正确而具体地实现它,这是你的驱动程序。

  1. 验证JDBC驱动程序的版本以及
  2. 的JDBC驱动程序类型(Thin或OCI)
  3. oracle sitehere下载新jar。
  4. 另外,在寻找驱动程序之前,请尝试使用oracle.jdbc.OracleTypes

    e.g。 cn.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);