org.eclipse.persistence.exceptions.DatabaseException内部异常:java.sql.SQLSyntaxErrorException:ORA-00911:无效字符

时间:2014-02-27 04:55:35

标签: java sql oracle jpa

查询得到了很好的执行,但问题与JPA。请帮助我找到错误。 如果我在Oracle SQL客户端中单独执行但是应用程序出错,则查询效果很好。

正如Eclipse所说的那样,我在这一行中遇到了异常

return genDODetails(pSess.executeQuery(rq));

查询:

SELECT DOD.ID AS DODID,ORDD.ID AS ORDDID,DOD.SHIPQTY AS DOQTY,DOD.BUYERCODE AS BUYERCODE,DOD.BUYERPARTNUM AS BUYERPARTNUM,
        DOD.BUYERPARTDESC AS BUYERPARTDESC,DOD.LINENUM AS DOLINENUM,DOD.LINEREVNUM AS LINEREVNUM,
        DOD.LINEINDICATIOR AS LINEINDICATOR,DOD.ORDLINENUM AS ORDLINENUM,ORDD.SHIPQTY AS SHIPPEDQTY,
        DOD.RSPREMARK1 AS SUPREMARK,DOD.ORDNUM AS PONUM
         FROM RDT_DELIVERYORDERDETAIL DOD,RDT_ORDERDETAIL ORDD ,RDT_ORDER ORDM
        WHERE  ORDD.LATEST =1
        AND ORDM.LATEST =1 
        AND ORDM.ID = ORDD.ORDID
        AND ORDD.RESPSTR1 ='EP'
        AND ORDD.LINENUM = DOD.ORDLINENUM
        AND ORDM.DOCNUM = DOD.ORDNUM
        AND DOD.LATEST =1
        AND CONTROLLERID =(SELECT ID FROM RDT_ORGANIZATION WHERE OUCODE ='yes' AND PARENTID IS NULL)
        AND DOD.DOID = 72
        ORDER BY DODID DESC;

JPA执行代码:

public List<DODetail> getDODetails(Map<String,Object> hparams) throws Exception
    {
        String sqlQuery= pSess.getSQLString4NamedQuery("DO_VIEW_DETAIL");   
        String doid = hparams.get("DOID")!=null ?(String)hparams.get("DOID"):"";
        Hashtable<String,Object> dbparams=new Hashtable();          
        dbparams.put(":DOID",doid);     
        sqlQuery = (String)pSess.getParamQuery(sqlQuery, dbparams);
        ReportQuery rq=new ReportQuery();
        rq.setReferenceClass(DODetail.class);


        rq.addAttribute("DODID");
        rq.addAttribute("ORDDID");
        rq.addAttribute("DOQTY");
        rq.addAttribute("BUYERCODE");
        rq.addAttribute("BUYERPARTNUM");
        rq.addAttribute("BUYERPARTDESC");
        rq.addAttribute("DOLINENUM");
        rq.addAttribute("LINEREVNUM");
        rq.addAttribute("LINEINDICATOR");
        rq.addAttribute("ORDLINENUM");
        rq.addAttribute("SHIPPEDQTY");
        rq.addAttribute("SUPREMARK");
        rq.addAttribute("PONUM");

        rq.setSQLString(sqlQuery);

        return genDODetails(pSess.executeQuery(rq));
    }   
    private List<DODetail> genDODetails(Object obj)throws Exception
     {
         if(obj==null ) return null;

         List newList = (List)obj;
         Iterator it = newList.iterator();
         List<DODetail> doDetails = new ArrayList<DODetail>();

        while(it.hasNext())
         {
            ReportQueryResult rs=(ReportQueryResult)it.next();
            DODetail order=new DODetail();  
            order.setId(rs.get("DODID")!=null?((BigDecimal)rs.get("DODID")).longValue():new Long(0));
            order.setRefid(rs.get("ORDDID")!=null?((BigDecimal)rs.get("ORDDID")).longValue():new Long(0));
            order.setShipqty(rs.get("DOQTY")!=null?(BigDecimal)rs.get("DOQTY"):new BigDecimal(0));
            order.setBuyercode(rs.get("BUYERCODE")!=null?(String)rs.get("BUYERCODE"):"");
            order.setBuyerpartnum(rs.get("BUYERPARTNUM")!=null?(String)rs.get("BUYERPARTNUM"):"");
            order.setCategory(rs.get("BUYERPARTDESC")!=null?(String)rs.get("BUYERPARTDESC"):"");
            order.setLinenum(rs.get("DOLINENUM")!=null?((BigDecimal)rs.get("DOLINENUM")).longValue():new Long(0));
            order.setLinerevnum(rs.get("LINEREVNUM")!=null?(String)rs.get("LINEREVNUM"):"");
            order.setLineindicator(rs.get("LINEINDICATOR")!=null?(String)rs.get("LINEINDICATOR"):"");
            order.setOrdlinenum(rs.get("ORDLINENUM")!=null?((BigDecimal)rs.get("ORDLINENUM")).toPlainString():"");
            order.setAssignqty(rs.get("SHIPPEDQTY")!=null?(BigDecimal)rs.get("SHIPPEDQTY"):new BigDecimal(0));
            order.setRspremark1(rs.get("SUPREMARK")!=null?(String)rs.get("SUPREMARK"):"");
            order.setOrdnum(rs.get("PONUM")!=null?(String)rs.get("PONUM"):"");          
            doDetails.add(order);
         }
         return doDetails;
     }

1 个答案:

答案 0 :(得分:1)

确保在执行之前,您的查询字符串中没有trailing semicolon。 因为,它不是必需的,这是导致此错误的可能原因之一。

使用OCI驱动程序向数据库发送查询时不需要。只有在SQL*Plus中手动执行时才需要将sql推送到数据库引擎执行。