4 Replies Latest reply on Jul 24, 2003 10:37 AM by 3004

    Query Date Column

    3004
      Hello,

      I try to make some simple date query to the db. here is my code,

      Extent mags = pm.getExtent (TransactionItem.class, false);
                     Query query = pm.newQuery (mags, filter);
                     System.err.println("declarePara " + declarePara);
                     System.err.println("filter " + filter);
                     query.declareImports("import java.util.Date;");
                     query.declareParameters (declarePara);
                     Collection jdoResult = (Collection) query.execute (startDate);







        • 1. Re: Query Date Column
          3004
          pike wrote:

          Hello,

          I try to make some simple date query to the db. here is my code,

          Extent mags = pm.getExtent (TransactionItem.class, false);
          String filter = " (journalDate >= d1)";
               Query query = pm.newQuery (mags, filter);
               query.declareImports("import java.util.Date;");
               query.declareParameters ("Date d1");
               Collection jdoResult = (Collection) query.execute (new Date());


          when I executed the code, I got the following exception,

          com.solarmetric.kodo.runtime.UserException: The type "(java.util.Date" as
          used in the variable/parameter declarations could not be found in the
          imports.
               at com.solarmetric.kodo.query.QueryImpl.bindClasses(QueryImpl.java:1024)
               at
          com.solarmetric.kodo.query.QueryImpl.bindParameterClasses(QueryImpl.java:983)
               at
          com.solarmetric.kodo.query.QueryImpl.internalCompile(QueryImpl.java:465)
               at
          com.solarmetric.kodo.query.QueryImpl.getAccessPathClasses(QueryImpl.java:1168)
               at
          com.solarmetric.kodo.query.QueryImpl.executeQueryWithMap(QueryImpl.java:581)
               at com.solarmetric.kodo.query.QueryImpl.executeWithMap(QueryImpl.java:540)
               at
          com.solarmetric.kodo.query.QueryImpl.executeWithArray(QueryImpl.java:526)


          What did I do wrong?

          and Is it possible not to use parameter?
          I tried
          Date startDate = new java.util.Date();
          filter = "journalDate >= " + startDate;
          Extent mags = pm.getExtent (TransactionItem.class, false);
          Query query = pm.newQuery (mags, filter);
          Collection jdoResult = (Collection) query.execute ();

          It didn't work either. Can anyone give me a right sample?

          thanks,


          pike
















          • 2. Re: Query Date Column
            3004
            Pike,

            In looking at the exception, it looks like you might have attempted to
            import "(java.util.Date" instead of "java.util.Date".

            Can you verify that there is no parenthesis in your import?

            -Patrick

            On Thu, 24 Jul 2003 03:05:31 +0000, pike wrote:
            pike wrote:

            Hello,

            I try to make some simple date query to the db. here is my code,

            Extent mags = pm.getExtent (TransactionItem.class, false);
            String filter = " (journalDate >= d1)";
                 Query query = pm.newQuery (mags, filter);
                 query.declareImports("import java.util.Date;");
                 query.declareParameters ("Date d1");
                 Collection jdoResult = (Collection) query.execute (new Date());


            when I executed the code, I got the following exception,

            com.solarmetric.kodo.runtime.UserException: The type "(java.util.Date" as
            used in the variable/parameter declarations could not be found in the
            imports.
                 at com.solarmetric.kodo.query.QueryImpl.bindClasses(QueryImpl.java:1024)
                 at
            com.solarmetric.kodo.query.QueryImpl.bindParameterClasses(QueryImpl.java:983)
                 at
            com.solarmetric.kodo.query.QueryImpl.internalCompile(QueryImpl.java:465)
                 at
            com.solarmetric.kodo.query.QueryImpl.getAccessPathClasses(QueryImpl.java:1168)
                 at
            com.solarmetric.kodo.query.QueryImpl.executeQueryWithMap(QueryImpl.java:581)
                 at com.solarmetric.kodo.query.QueryImpl.executeWithMap(QueryImpl.java:540)
                 at
            com.solarmetric.kodo.query.QueryImpl.executeWithArray(QueryImpl.java:526)


            What did I do wrong?

            and Is it possible not to use parameter?
            I tried
            Date startDate = new java.util.Date();
            filter = "journalDate >= " + startDate;
            Extent mags = pm.getExtent (TransactionItem.class, false);
            Query query = pm.newQuery (mags, filter);
            Collection jdoResult = (Collection) query.execute ();

            It didn't work either. Can anyone give me a right sample?

            thanks,


            pike
            --
            Patrick Linskey
            SolarMetric Inc.

            • 3. Re: Query Date Column
              3004
              It's not in the imports but There is a parenthesis in declareParameters.
              I think I know what I did wrong. thanks.


              Could you give me a simple example for directly using filter rather than
              parameters?

              pike



              Patrick Linskey wrote:
              Pike,
              In looking at the exception, it looks like you might have attempted to
              import "(java.util.Date" instead of "java.util.Date".
              Can you verify that there is no parenthesis in your import?
              -Patrick
              On Thu, 24 Jul 2003 03:05:31 +0000, pike wrote:
              pike wrote:

              Hello,

              I try to make some simple date query to the db. here is my code,

              Extent mags = pm.getExtent (TransactionItem.class, false);
              String filter = " (journalDate >= d1)";
                   Query query = pm.newQuery (mags, filter);
                   query.declareImports("import java.util.Date;");
                   query.declareParameters ("Date d1");
                   Collection jdoResult = (Collection) query.execute (new Date());


              when I executed the code, I got the following exception,

              com.solarmetric.kodo.runtime.UserException: The type "(java.util.Date" as
              used in the variable/parameter declarations could not be found in the
              imports.
                   at com.solarmetric.kodo.query.QueryImpl.bindClasses(QueryImpl.java:1024)
                   at
              com.solarmetric.kodo.query.QueryImpl.bindParameterClasses(QueryImpl.java:983)
                   at
              com.solarmetric.kodo.query.QueryImpl.internalCompile(QueryImpl.java:465)
                   at
              com.solarmetric.kodo.query.QueryImpl.getAccessPathClasses(QueryImpl.java:1168)
                   at
              com.solarmetric.kodo.query.QueryImpl.executeQueryWithMap(QueryImpl.java:581)
                   at com.solarmetric.kodo.query.QueryImpl.executeWithMap(QueryImpl.java:540)
                   at
              com.solarmetric.kodo.query.QueryImpl.executeWithArray(QueryImpl.java:526)


              What did I do wrong?

              and Is it possible not to use parameter?
              I tried
              Date startDate = new java.util.Date();
              filter = "journalDate >= " + startDate;
              Extent mags = pm.getExtent (TransactionItem.class, false);
              Query query = pm.newQuery (mags, filter);
              Collection jdoResult = (Collection) query.execute ();

              It didn't work either. Can anyone give me a right sample?

              thanks,


              pike
              --
              Patrick Linskey
              SolarMetric Inc.
              • 4. Re: Query Date Column
                3004
                The only way to compare on a Date in a query is to pass it as a parameter.