Date format /structure for JDBC

Hi, can anyone tell be what format a date should be in when querying a database. I have some old code that was transfered to a new app server which follows Java standards very strictly. Now it gives me problems when comparing dates, for example a query that finds records for a date BETWEEN two other dates. The old format was dd-mon-yyyy, but this doesn't work anymore and neither does dd-mon-yy OR yyyy-mon-dd. When I do the query in the text editor(SQL Plus) it works, but not within the Java code.
Any ideas?
Thanks

I see what you mean now. Yes, format matters then. Your HTML page will assume that the string that's typed into the text box will be a valid date string using a format that you choose.
You should turn that String into a java.util.Date using java.text.DateFormat.parse(). Be sure to call setLenient(false) on the DateFormat instance before you call parse(). That way you'll get a java.text.ParseException if the String isn't valid according to your pattern and you can send an error page back to the client. (OR validate the pattern on the client side using JavaScript before the page is submitted.)
Once you've got a valid java.util.Date for your DateFormat instance, create a java.sql.Date to pass to the ava.sql.PreparedStatement.setDate method.
Warner's point is that by the time you get around to passing the java.sql.Date to PreparedStatement, all that validation stuff is supposed to be done.

Similar Messages

  • Question about Sender and Receiver Structure for JDBC

    Dear All,
    I want to know why there is a fixed format for sender and receiver structure for JDBC. why cant we use the structure like what we want? explain me in detail.
    Thanks

    Good Question:
    We have to create our data structure based on the existing database table structure. While reading or writing , JDBC adapter convert our data type structure in to SQL Query Statements that matches Table structure.

  • Multiple STATEMENT nodes in target structure for JDBC adapter

    Hi All,
    I have a file to JDBC scenario . At the receiver side we need to update two tables simultaneously .
    So in the target structure for JDBC , is it possible to have two STATEMENT nodes , so that 2 tables can be updated simultaneously.
    Please help.
    Thanks & Regards,
    Loveena.

    Hi,
    U can do tht..please see below link..
    http://help.sap.com/saphelp_nw04/Helpdata/EN/bc/bb79d6061007419a081e58cbeaaf28/frameset.htm
    Regards,
    Manisha

  • Date Formatting error in JDBC adapter

    Hi,
    While inserting date using a Receiver JDBC Adapter i am getting a "Month not valid" error can anyone please tell me how do i pass date in the required format. Database is Oracle.

    Hi Vinay,
    Oracle's default format for DATE is "DD-MON-YY"
    With the functions to_char and to_date, a date format can be used. Example:
    select to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') from dual;
    will return something like: 24/03/2006 14:36:43
    Regards,
    Prateek

  • Custom Data Formatting Gone for Dates

    Another new aspect of the updated Numbers app for OS X is the loss of customizing data formats.  There are more options via a drop down, but there's less customization.  For example.  I had a use case where I'd take a column full of dates and would replicate it so the same data was in two columns.  I then was able to customize the first column of dates to use a month shortcode only so it would render "Jan, Feb, Mar, Apr..." depending on the data in that column.  The next colum with the same data I'd then customize to show only the day of the month.  See the example below.
    Date
    Column 1
    Date
    Column 2
    Jan
    4
    Mar
    15
    Oct
    23
    Presently, neither the shortnames for months by themselves nor the day of the month by itself is available as an option when working in the Data Format panel.
    I'm assuming the customization was killed, but if someone knows if that's hidden elsewhere, please let me know!

    Hi Bret,
    I don't know the answer to your actual question as I tend to later adoption, and am not yet using Numbers 3.0, but here's a workaround (with some limitations, noted below).
    Limitations:
    Requires that the values in the cells are created by formulas, or can be created by formulas referencing another cell.
    The resulting values will be a text string (column A) or a numeric value (column B), not a Date and Time value.
    A: =LEFT(MONTHNAME(MONTH(formula)),3)
    B: =DAY(formula)
    In each, formula is the existing formula used to determine the D&T value currently in the cell.
    Regards,
    Barry

  • Date format (YYMMDD ) for the file

    HI All,
    I need to place a file with file name that should include the date in the format YYMMDD. Currently the format is DDMMYY.
    How can i do that?
    Thanks In advance!!

    Perhaps by changing the date format in the personal settings of the user that creates the file.
    Check transaction su01 - username - defaults
    Kind regards,
    Mark

  • DATE FORMAT Conversion FOR SQL Reports

    Hi,
    Am building a report and am stuck here where this piece of code that throws the following error
    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
    My query goes some thing like this
    DECLARE @StartDate varchar(15),
    @EndDate Varchar(15)
    SELECT @StartDate = '01/08/2014',
    @EndDate = '31/08/2014'
    SELECT DISTINCT
    [Operation] = CASE WHEN p.DATE_OF_START BETWEEN @StartDate AND @EndDate THEN 'Add'
    ELSE 'Update' END
    FROM SNZ_HR_Reporting_POSMGNT as s
    LEFT OUTER JOIN PERSON as p on s.EMP_NO = p.EMP_NO
    WHERE s.CHANGE_DATE BETWEEN @StartDate AND @EndDate
    The date format in the column DATE_OF_START  is like yyyy-mm-dd 00.00.00.000 .
    My question is how to convert this format to dd/mm/yyyy format and execute the queries
    Many Thanks,
    Bhanu

    SQL Date Format:
    http://www.sql-server-helper.com/tips/date-formats.aspx
    Please Mark This As Answer if it helps to solve the issue

  • Date format function for 5/2/2010 9:46:00 AM?

    Hi,
    I want to convert date format in dd/mm/yyyy hh:mm:ss AM/PM format.
    Any suggestion?
    Thanks.

    You can use:
    <?format-date:xdoxslt:sysdate_as_xsdformat();'SHORT_TIME';’GMT-5’?>
    Your date must be in ISO format, please read below
    Reference:
    http://download.oracle.com/docs/cd/E10415_01/doc/bi.1013/e12187/T421739T481157.htm#4535403
    regards
    Jorge

  • Invalid data format error for CLOB

    I am trying to migrate a piece of code from WLS 8.1.2 to WLS 8.1.5.
    WLS 8.1.2 has ojdbc14.jar with version "Oracle JDBC Driver version - 9.0.2.0.0"
    WLS 8.1.5 has ojdbc14.jar with version "Oracle JDBC Driver version - 10.1.0.4.0"
    In the older version, I am storing an encrypted string value in a clob and saving in the db.
    When I try the same in the new code, it displays an error that the data is not of the proper format.
    If I read any data entered using the older application, in the new one, it is still valid.
    But, if I enter a new value using WLS 8.1.5, only those are invalid.
    I even tried deploying the application with the old and new ojdbc14.jar files with it. In either case, it still gives an error. If I use the later version of ojdbc14.jar, the method getAsciiStream() is deprecated.
    How can I make my code independent of the version of ojdbc14.jar and store and read the clob?

    Rohit B wrote:
    I am trying to migrate a piece of code from WLS 8.1.2 to WLS 8.1.5.
    WLS 8.1.2 has ojdbc14.jar with version "Oracle JDBC Driver version - 9.0.2.0.0"
    WLS 8.1.5 has ojdbc14.jar with version "Oracle JDBC Driver version - 10.1.0.4.0"
    In the older version, I am storing an encrypted string value in a clob and saving in the db.
    When I try the same in the new code, it displays an error that the data is not of the proper format.
    If I read any data entered using the older application, in the new one, it is still valid.
    But, if I enter a new value using WLS 8.1.5, only those are invalid.
    I even tried deploying the application with the old and new ojdbc14.jar files with it. In either case, it still gives an error. If I use the later version of ojdbc14.jar, the method getAsciiStream() is deprecated.
    How can I make my code independent of the version of ojdbc14.jar and store and read the clob?Hi. You are suffering with the evolution of Oracle's driver. If you can make a standalone
    program that contains some data, inserts it and extracts it an compares it and proves
    the bug, we can open a case with Oracle. In general you want to use their latest driver,
    but if you can't keep up with their bugs/fixes, you can always keep using the same version
    of the driver everywhere. The way to do that is not to put the driver in you packages,
    but simply to keep the version you want in the weblogic installation's server\lib
    directory (ojdbc14.jar)
    Joe

  • Date format Mask for CHAR datatype

    hi
    i want to assign a format mask like 'dd/mm/yyyy' to a field which has char datatype can i ?

    The quickest answer to your question is to try it! :-) If you click on the Format Mask property of your Text Item and then press F1 Forms will display the Format Mask Help information for this property. All of the valid combinations for a Text Field Format Mask will be displayed.
    To answer your question, you can put a format mask on a Text Item that can enforce the basic format of 'DD/MM/YYYY', but you could get data like: 99/99/9999. You would have to write code in a When-Validate-Item trigger that would ensure the user has entered a valid date.
    Hope this helps.
    Craig...

  • Message structure for JDBC receiver adaptor

    Hi experts,
    IN JDBC reciever adaptor i want to insert 3 fields in table.....!
    the structure i have created is as follows:
    TestReceiver
    StatementName
    Test
        Action (attribute)
       TABLE
       access(1-unbound)
           FirstName
           MiddName
           LastName
    and source is
    testSender
      Row(1-unbound)
        FirstName
        MiddleName
        LastName
    I am getting error ="MAPPING">EXCEPTION_DURING_EXECUTE
    can somebody plz tell me what is wrong?
    Thanks
    Rohan

    <?xml version="1.0" encoding="utf-8"?>
    <ns:TestSender xmlns:ns="http://test.com/EmpData">
    <Recordset>
         <Row>
              <FirstName>Aaa</FirstName>
              <MiddleName>Bbbbb</MiddleName>
              <LastName>Ccccc</LastName>
         </Row>
    </Recordset>
    </ns:TestSender>

  • Modify DATE format only for a column

    DB table has two or more columns of DATE type of which a column representing "Date of Birth" should not be of the format of TIMESTAMP . When queried it should return "mm/dd/yyyy" format without 'hh:mm:ss' . The others should be as usual.
    This is to ensure no changes in the applications querying this columns
    Any hints appreciated
    Thanks

    It depends on NLS_DATE_FORMAT and NLS_TIMESTAMP_FORMAT that is set in the database or session and the datatye used in the table, here is an example:-
    U1@BABU>  CREATE TABLE TEST_TAB (DATE1 DATE, DATE2 TIMESTAMP);
    Table created.
    U1@BABU> INSERT INTO TEST_TAB VALUES (SYSDATE,SYSDATE);
    1 row created.
    U1@BABU>  COMMIT;
    Commit complete.
    U1@BABU> SELECT * FROM TEST_TAB;
    DATE1 DATE2
    22-DEC-06 22-DEC-06 11.44.18.000000 AM
    U1@BABU> SELECT * FROM NLS_SESSION_PARAMETERS;
    PARAMETER                      VALUE
    NLS_LANGUAGE                   AMERICAN
    NLS_TERRITORY                  AMERICA
    NLS_CURRENCY                   $
    NLS_ISO_CURRENCY               AMERICA
    NLS_NUMERIC_CHARACTERS         .,
    NLS_CALENDAR                   GREGORIAN
    NLS_DATE_FORMAT DD-MON-RR
    NLS_DATE_LANGUAGE              AMERICAN
    NLS_SORT                       BINARY
    NLS_TIME_FORMAT                HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY              $
    NLS_COMP                       BINARY
    NLS_LENGTH_SEMANTICS           BYTE
    NLS_NCHAR_CONV_EXCP            FALSE
    17 rows selected.
    U1@BABU> ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS';
    Session altered.
    U1@BABU> SELECT * FROM TEST_TAB;
    DATE1 DATE2
    22-DEC-2006 11:44:18 22-DEC-06 11.44.18.000000 AM
    U1@BABU> SELECT TO_CHAR(DATE1,'MON-DD-YYYY HH24:MI:SS') DATE1, TO_CHAR(DATE2,'Month DD YYYY') DATE2
    FROM TEST_TAB;
    DATE1                DATE2
    DEC-22-2006 11:44:18 December  22 2006

  • Independently configure date format for XML/JSON serialization

    How do I configure the date format independently for each of my date fields?
    For example, let's say I have a CustomerOrder class with more than 1 java.util.Date fields in it.
    I need to be able to render like this:
    <customerOrder>
    <orderDate>2013-01-04T20:50:42.769Z</orderDate>
    <user>Bob</lastUpdateUser>
    <state>CO</state>
    <estShipDate>2013-01-04</estShipDate>
    </customerOrder>
    So one of the dates may not care about the hh:mm:ss.
    i.e. I cannot format every date the same way.
    Any ideas?
    This is my technology stack:
    - Tomcat 7
    - Jersey 1.16
    - Enunciate 1.26.2
    - Spring 3.1.2
    - Hibernate 4.1.7
    - JPA 2.0.3

    Otis,
    A "java.sql.Date" contains only a date, whereas a "java.sql.Timestamp" contains both date and time. So retrieve the data (from the database) as a "Timestamp" and not as a "Date".
    Perhaps if you'd care to post the relevant part of your code and show what you are getting and what you want to get, I may be able to help you further.
    Here's a small (uncompiled and untested) example:
    Connection conn = // However you get it.
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select sysdate from dual");
    if (rs.next()) {
      Timestamp ts = rs.getTimestamp(1);
    }Good Luck,
    Avi.

  • ORA-01821: date format not recognized Error in PL/SQL report-4.0

    Hi,
    I am using Apex 4.0 and i have a Classic report(function returning query) which selects a date column.
    The query runs at the backend and gives the output.
    But when i run the report on the page, i get the error
    report error:
    ORA-20001: Error fetching column value: ORA-01821: date format not recognizedThe values for the date column are like this 14-MAR-13,01-FEB-13 etc... Everything seems to be right.
    But I have no idea why this error occurs.
    Thanks
    Divya

    Aren't these errors annoying! But there's a data / format mismatch for sure. What I need to see -- and what will tell you what is wrong -- is
    1) exactly what the data is and
    2) exactly what the format string is that is being used to convert it.
    The values for the date column are like this 14-MAR-13,01-FEB-13 etc... Question: Is this the source data or the target data ( what it's supposed to look like after being converted)?
    Let's start there:
    What is the source? Is it a DB column? Is it type date or VARCHAR2 or what?
    If VARCHAR2, then give us an example of the data that is failing.
    What is the format -- I assume there is one -- being used to convert the data?
    Are you doing a TO_CHAR or a TO_DATE?
    Give us lots of detail, please. Then it should be easy to solve.
    Regards,
    Howard

  • Date format in obiee reports

    HI guys
    i got two obiee server running in our env . both are identical . on one server when ever we rite any report with date column in it it comes up with dd/mm/yyyy output on another server if we right any report all the date column comes with dd mon yyyy format .. i want both of them should show date like dd mon yyyy format .. i checked all the conf files are both are looking same still not able to figure out where should i change for this to work .
    please let me know if you need more info from my end.
    Regards,
    Dev

    HI Kishore
    Thanks for your reply i checked all the things but with no success. do think there could be any other place where i should check .
    1. nqsconfig date format
    its same for both the two installations
    DATE_TIME_DISPLAY_FORMAT = "yyyy/mm/dd hh:mi:ss" ;
    DATE_DISPLAY_FORMAT = "yyyy/mm/dd" ;
    TIME_DISPLAY_FORMAT = "hh:mi:ss" ;
    2. make sure that you didn't save date format in column properties from front-end
    Just checked and we havan't saved anything in column properties .. even i created new report as well but still format was same ..
    3. Did you mention anything in connection pool settings to set date format.
    no we havan't mention anything in connection pool
    4. Make sure that you are connecting to same database, and date format set for date is same here and there
    yahh both the two installatiosn are connected to same database .. but not sure about "date format set for date is same here and there
    " hw i can check this
    finally, check this: http://108obiee.blogspot.com/2009/04/changing-date-format-mask-in-javascript.html
    no its not on one column .. its to all the date format columns on all the reports .. so i think its not case with me .
    please let me know if you need more info
    Regards,
    Dev

Maybe you are looking for