包装异常:org.springframework.jdbc.BadSqlGrammarException:PreparedStatementCallback;糟糕的SQL语法

时间:2012-12-03 21:32:01

标签: java spring struts sqlexception

我有这样的DAO,

public String getCaseTypeById(String caseIdNumber) {
        String caseType = null;

        SqlQuery caseQuery = 
            new PQuery(getDataSource());
        System.out.println("caseIdNumber   --"+caseIdNumber);
        caseType = (String)caseQuery.findObject(caseIdNumber);
        System.out.println("before return");

        return caseType;
    }

和pQuery是,

public PlanQuery(DataSource dataSource)
{
    super();
    setDataSource(dataSource);
    BQueries bQueries = new BQueries();

    setSql(bQueries.getSelectStandardCaseTypeQuery());
    declareParameter(new SqlParameter("caseIdNumber",
            Types.NUMERIC));
    compile();
}

其中getSelectStandardCaseTypeQuery是

public String getSelectStandardCaseTypeQuery() {

String selectCaseTypeByCaseId = null;

        selectCaseTypeByCaseId = 
            " SELECT ct.C_CODE as c_code " + 
            "  FROM  " + getSchemaName() + ".csummary cs, " + 
                getSchemaName() + ".ctype ct " +
            "   WHERE cs.c_number = ? " + 
            "   AND UPPER(ct.C_DESC_TEXT) = UPPER(cs.C_TYPE) ";

    return selectCaseTypeByCaseId;
}

现在上面的返回工作正常。控件返回到DAO,在DAO中,sysout被打印,但之后我得到了异常,

[SELECT ct.C_CODE as c_type_code FROM gpt.csummary cs,gpt.ctype ct WHERE cs.c_number =? AND UPPER(ct.C_DESC_TEXT)= UPPER(cs.C_TYPE)];嵌套异常是java.sql.SQLException:ORA-00942:表或视图不存在

at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

包装异常: org.springframework.jdbc.BadSqlGrammarException:PreparedStatementCallback;错误的SQL语法[SELECT ct.C_CODE as c_type_code FROM gpt.csummary cs,gpt.ctype ct WHERE cs.c_number =? AND UPPER(ct.C_DESC_TEXT)= UPPER(cs.C_TYPE)];嵌套异常是java.sql.SQLException:ORA-00942:表或视图不存在。

但是当我在蟾蜍中执行相同的操作时,一切正常。我看到DB conenction架构的一切都是正确的指向。但是为什么它在DAO中的finObject中失败了。任何输入?

1 个答案:

答案 0 :(得分:0)

看起来你必须使用:

select * from schema.table_name