1 Reply Latest reply: Mar 5, 2012 10:10 AM by User739461-Oracle RSS

    String literal is not properly closed by a double-quote

    user545194
      Hi,

      In my Java Class, this message appears:

      String literal is not properly closed by a double-quote
      LINE: The red part of the statement.

      Please help! Thanks!
      package demo;
      
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      
      public class Flights {
           
           private EntityManagerFactory emf;
            
          private EntityManager getEntityManager() {
              if (emf == null) {
                  emf = Persistence.createEntityManagerFactory("Flights");
              }
              return emf.createEntityManager();
          }
       
          public Flights[] getFlights() {
              EntityManager em = getEntityManager();
              try {
                  javax.persistence.Query q = em.createQuery("SELECT /*+ INDEX(lh_master_q lh_master_pk)*/ DISTINCT to_char(FD.FLIGHT_DATE, 'DY')||'.'|| FD.FLIGHT_DATE AS DATE_HEADER,
        FD.FLIGHT_DATE AS TRAVEL_DATE,
        B.CITY                       AS LEAVING,
        LM.STD                       AS DEPART,
        C.CITY                       AS ARRIVING,
        LM.STA                       AS ARR,
        LM.FNR                       AS FLIGHT,
        E.CARRIER                    AS AIRLINE,
        LM.ACTYPE                    AS AIRCRAFT,
        LM.ACTYPEFULLNAME            AS EQUIP,
        LM.STD ||' '|| LM.DEP ||' - '|| LM.STA ||' '|| LM.ARR AS SCHEDULE,
        B.CITY ||' - '|| C.CITY AS ROUTE
        MAX(CASE WHEN FA.BOOKING_CLASS = 'S' AND p_num_adt > 1 THEN (ROUND(FA.LH_FARE_EUR, 2)* p_num_adt) END) AS ECONOMY_SAVER,
        MAX(CASE WHEN FA.BOOKING_CLASS = 'H' AND p_num_adt > 1 THEN (ROUND(FA.LH_FARE_EUR, 2)* p_num_adt) END) AS ECONOMY,
        MAX(CASE WHEN FA.BOOKING_CLASS = 'B' AND p_num_adt > 1 THEN (ROUND(FA.LH_FARE_EUR, 2)* p_num_adt) END) AS ECONOMY_FLEXIBLE,
        MAX(CASE WHEN FA.BOOKING_CLASS = 'Z' AND p_num_adt > 1 THEN (ROUND(FA.LH_FARE_EUR, 2)* p_num_adt) END) AS BUSINESS,
        MAX(CASE WHEN FA.BOOKING_CLASS = 'D' AND p_num_adt > 1 THEN (ROUND(FA.LH_FARE_EUR, 2)* p_num_adt) END) AS BUSINESS_FLEXIBLE,
        MAX(CASE WHEN FA.BOOKING_CLASS = 'F' AND p_num_adt > 1 THEN (ROUND(FA.LH_FARE_EUR, 2)* p_num_adt) END) AS FIRST_CLASS
      FROM LH_MASTER_Q LM, LH_FLIGHT_DATE FD, AIRPORTS_LOOKUP B, AIRPORTS_LOOKUP C, CARRIERS E, LH_FARES FA, LH_SERVICE_CLASS SC, LH_CABIN_CLASS CC
      WHERE LM.ROWNR = FD.FLIGHT_LEG_ID
         AND LM.DEP = FA.FROM_AP
         AND LM.ARR = FA.TO_AP
         AND LM.DEP = B.IATA_CODE
         AND LM.ARR = C.IATA_CODE
         AND LM.AL = E.CARRIER_CODE
         AND FA.BOOKING_CLASS = SC.BKG_CLASS_ID
         AND SC.CABIN_CLASS_ID = CC.CABIN_CLASS_ID
         AND LM.ACTYPE = FD.AIRCRAFT_TYPE
         AND B.CITY_CODE = :p_leaving
         AND C.CITY_CODE = :p_arriving
         AND CC.CABIN_CLASS_NAME = :p_class
         AND E.CARRIER = :p_airline
         AND FD.FLIGHT_DATE = :p_outbound
      GROUP BY FD.FLIGHT_DATE,
               to_char(FD.FLIGHT_DATE, 'DY')||'.'|| FD.FLIGHT_DATE,
               B.CITY, 
               LM.STD, 
               C.CITY, 
               LM.STA, 
               LM.FNR,
               E.CARRIER,
               LM.ACTYPE,
               LM.ACTYPEFULLNAME,
               LM.STD ||' '|| LM.DEP ||' - '|| LM.STA ||' '|| LM.ARR,
               B.CITY ||' - '|| C.CITY,
               to_char(FD.FLIGHT_DATE, 'DY')
      ORDER BY Depart;");
                  return (Flights[]) q.getResultList().toArray(new Flights[0]);
              } finally {
                  em.close();
              }
          }
      }
        • 1. Re: String literal is not properly closed by a double-quote
          User739461-Oracle
          From the Java specification (http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html#3.10.5):

          It is a compile-time error for a line terminator to appear after the opening " and before the closing matching ".

          In other words, string literals cannot span lines.

          You can use the concatenation operator ( + ) to fix this:

          String myLiteral = "A long line " +
          "Another long line " +
          "Another long line, etc.";

          If you're going to ever print out that string literal (like for debugging purposes), it would probably be better to have a return at the end of each line (\n):

          String myLiteral = "A long line\n" +
          "Another long line\n" +
          "Another long line, etc.";

          Edited by: user739461 on Mar 5, 2012 8:10 AM