在Select语句中ORA 00905缺少关键字

时间:2016-02-09 05:57:45

标签: sql keyword

try {
        st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        st3 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = st.executeQuery("select insp_no,ro_code, inspectiondate from keroseneheader where ro_code='" + cust_code + "' and status='NO' and inspectedby='" + em.ro_code + "'");

        if (rs.next()) 
        {
          session.setAttribute("insp_no", rs.getString("insp_no"));
          out.print(rs.getString("insp_no") + "#" + rs.getString("inspectiondate"));
        } 
        else
        {
          rs3 = st3.executeQuery("select * from keroseneheader where ro_code='" + cust_code + "' and inspectiondate>to_date('" + inspectdate + "','dd-mm-yyyy') and inspectedby='" + em.ro_code + "'");

          if (!rs3.next()) 
          {
            String query2 = "insert into keroseneheader(insp_no,ro_code,inspectiondate,status,inspectedby) values((select nvl(max(INSP_NO)+1,1) from keroseneheader),'" + cust_code + "',"
        + "to_date('" + inspectdate + "','dd-mm-yyyy'),'NO','" + em.ro_code + "')";
            boolean i = DbConn.insertupdatedata(query2, false);

           if (i) {
                st1 = con.createStatement();
                rs1 = st1.executeQuery("select insp_no,to_char(inspectiondate,'dd-mm-yyyy') inspectiondate from keroseneheader where ro_code=" + cust_code + " and status='NO' and inspectedby='" + em.ro_code + "'");

             if (rs1.next()) {
        session.setAttribute("insp_no", rs1.getString("insp_no"));
        out.print(rs1.getString("insp_no") + "#" + rs.getString("inspectiondate"));
                }
             }
        } 
        else {
        out.print("Invalid Date");
        }
       }

1 个答案:

答案 0 :(得分:-1)

更改此行

st1.executeQuery("select insp_no,to_char(inspectiondate,'dd-mm-yyyy') inspectiondate from keroseneheader

到此

st1.executeQuery("select insp_no,to_char(inspectiondate,'dd-mm-yyyy') as 'inspectiondate' from keroseneheader