How to convert JAVA. SQL. Date the DATE in the format DD/MM/YYYY to DD/MM/YYYY

I use an informix database that accepts the value of date as a DATE format...
the other part of my app takes date from the field in the format DD/MM/YYYY... so I have to convert my java.sql.date in marker AAAA/MM/JJ JJ/MM/AAAA marker of the same type before inserting into db...
but by using the parse method in SimpleDateFormat class can get the result format java.util.date...
and also using method format may result in the conversion of strings...

public class Dbop {
    static final java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("dd/MM/yyyy");
    public static void main(String[] args) throws Exception {
        java.util.Date ud = fmt.parse("31/12/2010");
        java.sql.Date sd = new java.sql.Date(ud.getTime());
        String formattedSqlDate = fmt.format(sd);
        System.out.println("result:"+formattedSqlDate);
    }
}

Tags: Oracle

Similar Questions

  • How to convert java.sql.ResultSet to intradoc.data.DataResultSet

    I used a MS jdbc driver to perform a query and got a java.sql.ResultSet.
    Now when I try this

    DRS DataResultSet = new DataResultSet();
    ResultSet rs = stmt.executeQuery (sqlString);
    Drs.Copy ((intradoc. (Data.ResultSet) rs);

    I get an error "ClassCastException.
    But they compile even without the cast.

    I also tried this:

    {while (RS. Next())}
    trace ("CPC" + rs.getString (1));
    String s = rs.getString (1);
    Vector v = new Vector < String > < String > ();
    v.Add (s);
    drs.addRow (v);
    }

    and I get an error
    Caused by: java.lang.Error:! syFailedAppendRow

    Is there a way to do it (or something)? Y at - it the javadoc for intradoc.data.DataResultSet?

    I'm using eclipse and JRE 1.5
    And injectors scanner stellant 10gr 4

    Thank you

    Published by: kgough on March 2, 2011 06:36

    If this does not work, you can always try something like this

    public static DataResultSet toDataResultSet(
         final java.sql.ResultSet p_resultset,
         final boolean p_closeAfterCopy
    ) throws SQLException {
    
         final ResultSetMetaData rsmd = p_resultset.getMetaData();
         final int columnCount = rsmd.getColumnCount();
    
         // get headings
         final String[] columnNames = new String[ columnCount ];
         final int[] columnTypes = new int[ columnCount ];
         for ( int i = 0 ; i < columnCount ; i++ ) {
              columnNames[ i ] = rsmd.getColumnName( i + 1 );
              columnTypes[ i ] = rsmd.getColumnType( i + 1 );
         }
    
         final DataResultSet dataResultSet = new DataResultSet( columnNames );
    
         while ( p_resultset.next() ) {
    
              Vector row = new Vector();
              for ( int i = 0 ; i < columnCount ; i++ ) {
    
                   final int fieldType = columnTypes[ i ];
    
                   //if ( fieldType != Types.CHAR || fieldType != Types.VARCHAR ) {
                   //     // if you want stuff other than string, do smart stuff here
                   //}
                   row.add( p_resultset.getString( i + 1 ) );
    
              }
              dataResultSet.addRow( row );
    
         }
    
         if ( p_closeAfterCopy ) {
              p_resultset.close();
         }
    
         return dataResultSet;
    
    }
    
  • SQL * Loader: load data in the format MM/DD/YYYY HH: mi: SS PM

    Please advice how to load data in the format MM/DD/YYYY HH: mi: SS PM in an Oracle Table using SQL * Loader.

    -Should what format I give in the control file?
    -What would be the type of column to create the table to load data.

    Examples of data below;

    MM/DD/YYYY HH: MI: SS PM

    14:40:20 09/12/2012
    29/11/2011 11:23:12

    Thanks in advance
    Avinash

    Astr0 wrote:
    Hello Srini,

    I tried with the date of creation as DATE data type, but I had an error like

    ORA-01830: date format picture ends before converting entire input string
    CREATION_DATE               "TO_CHAR(TO_DATE(:CREATION_DATE,'MM/DD/YYYY HH:MI:SS AM'),'DD-MON-YYYY HH:MI:SS AM')",
    

    Try

    CREATION_DATE "to_Date(:CREATION_DATE,'yyyy-mm-dd hh:mi:ss AM')",
    

    Does that help? It is charging correctly in the timestamp column

    REDA

  • Does not not for java.sql.Date sort field

    Hi Experts ADF,

    JDev version 11.1.1.7.0

    I use a POJO based datacontrol, who is dragged like a table on page JSFF. One of the field is a java.sql.Date data type in POJO.

    So for example in the table 4 values are there to this date field as

    2.2.2014

    3.2.2014

    31.1.2014

    to 31.12.2013

    So while sorting in ascending order, it should come as below

    to 31.12.2013

    31.1.2014

    2.2.2014

    3.2.2014

    And vice-versa.

    But if I click on sort it sorts by the first 2 digits only, and I'm under results for sorting (ascending)

    2.2.2014

    3.2.2014

    31.1.2014

    to 31.12.2013

    Please suggest on this. Thanks in advance.

    Thank you

    Animesh

    Hi This sorting has been solved by changing of java.util.Date.

    Yes his watch to the client as an outputText inside the table. Sorting option is there for af:column.

    Thank you

    Roy

  • In general, is it better to use java.sql.Date and java.sql.Timestamp instead of oracle.jbo.domain.Date?

    Hello world

    During playback of Oracle ADF Real World Developer's Guide, I noticed the dates match occurring in JDeveloper is different from what is the list in the book. JDeveloper is failing to oracle.jbo.domain.Date, but according to the book:

    DATEjava.sql.DateDATE type is mapped to java.sql.Date if the column in the table is a no time didn't need information zone.
    DATEjava.sql.TimestampDATE type is mapped to java.sql.Timestamp if the column in the table has a component "time" and that the client needs to zone information.
    TIMESTAMPjava.sql.TimestampThe TIMESTAMP type is mapped to java.sql.Timestamp if nanosecond precision is used in the database.

    In general, is it better to use java.sql.Date and java.sql.Timestamp instead of oracle.jbo.domain.Date? Using java.sql.Date and java.sql.Timestamp could save me some headaches conversion date. And, is there a place in JDeveloper to display these maps? I looked around and didn't see anything.

    Thank you.

    James

    User, what version of jdev we are talking about?

    In GR 11, 1 material versions db types date and timestamp are mapped to types of domain data that represents a wrapper for the native data types. The reason was that the framework can work with the domain types regardless of the underlying data type.

    Since Oracle 11 GR 2 maps the types DB to java types (default selection, you can change it when you create a model project, you can set the Data Type Mapping). Once the pilot has business components define you cannot change this setting it would break existing components such as eo or vo.

    So if you are working wit 11 GR 1 subject, you must use the domain types, if you work with GR 11, 2 or 12 c, you can use the domain types, but it is recommended to use the java type mapping.

    Timo

  • How to get the date in the format dd/mm/yyyy?

    Hello
    for this query:
    > select to_date (to_char (sysdate), ' dd/mm/yyyy') of double;
    I wanted to get a date in the format dd/mm/yyyy, but this query is not in the right format to date.
    How to get it?

    Why you are converting a date (it's a date in your table, right) tank and back to a date. When you want to display a date a certain way, you use to_char and specify the mask format to display the date as to_char (sysdate, 'dd-mm-yyyy'). Internally, dates are stored as bytes 7, you use to_char only for display purposes.

  • java.lang.ClassCastException:String cannot be cast to java.sql.Date

    I have a date component. MinValue named Id2 and the following code is to run a class cast exception indicating that the string value cannot be cast to a date sql

    java.sql.Date dateNeeded = (java.sql.Date) this.getId2 () .getValue ();

    can someone help me to overcome this problem.

    Thanks and greetings
    Janak

    Published by: new_to_ORACLE on February 18, 2011 16:56

    Published by: new_to_ORACLE on February 18, 2011 16:58

    the Date attribute is of type object oracle.jbo.domain.Date
    so, first try to cast to oracle.jbo.domain.Date. then to java.sql.Date object

    If you need to cast to another Date object, see this site:
    http://www.ecotronics.ch/webdesign/javadate.htm

    Published by: M.Jabr on February 19, 2011 11:53

  • How do I get the date in the format dd/mm/yyyy hh: mm IS

    Hi all
    I want to display the sysdate in the format mm/dd/yyyy hh: mm IS. Please help if anyone knows.
    select to_char(systimestamp at time zone 'EST','mm/dd/yyyy hh:mi tzr') from dual
    

    do you think that... ??

    Ravi Kumar

  • How to convert months to all THE PLUGS for example December 5, 2015 to December 5, 2015

    It must have an easy solution.

    My date indicator returns the format DD-MMM-yyyy.

    I need the MMM to be all caps.

    You haven't tried the function of capital letters?

  • Portal Oracle Gold: how to convert insert them in the update

    In my db goal there is no delete replicated.

    But sometimes, the same key is removed and inserted in the future.

    In this case, how to convert insert them in the update?

    Kind regards

    William

    I have

    If I use this option:

    RESOLVECONFLICT (INSERTROWEXISTS, (BY DEFAULT, OVERWRITE))

    ???

  • How to convert forms fillble to the ipad

    How to convert forms fillble to the ipad?

    Hi alusich,

    PDF forms on mobile are different form normal PDF forms, please refer to this KB doc. helps LiveCycle | Have a differentiation between Mobile Forms and PDF forms.

    If you want to create PDF forms for mobile devices, I recommend you to use LiveCycle designer helps LiveCycle | Mobile forms - developer.

    Kind regards

    Nicos

  • I have a protected PDF file. I have the password. How to convert to Word?  The export tool will fail because it has a password (even if the doc is open)

    I have a protected PDF file. I have the password. How to convert to Word?  The export tool will fail because it has a password (even if the doc is open)

    Hi stupiddonkey,

    You will need to remove the password from the file (using Acrobat, not reader) before you can convert it to Word. To do this, choose file > properties, and then click the Security tab choose no security in the context menu of the security method and enter the password when you are prompted.

    Best,

    Sara

  • I want to add fonts in DW from my own library how to convert InDesign and add the necessary css?

    I want to add my own library fonts (less manage fonts) how to convert InDesign and add the necessary css?

    You must ensure that your font licenses extend to the internet.  Many do not.

    If you are sure that you can use your fonts on the web, use font squirrel to create a kit.

    Custom Web fonts

    Nancy O.

  • What is the best way to obtain a string that represents a date in the format mm/dd/yyyy

    What is the best way to obtain a string that represents a date in the format mm/dd/yyyy

    It would be good if I could generate this string using the static methods of a class.






    You can use date formatter:

    Import mx.formatters.DateFormatter;
    ...

    var trainer: DateFormatter = new DateFormatter();
    formatter.formatString = "YYYY/MM/DD JJ:NN:SS;
    var today: Date = new Date();
    trace (formatter.format (now));

  • We had to find the date in the format "DD-MM-YYYY" and "DD/MM/YYYY '.

    Hello world

    I need to find the hire_date in the format "dd-mm-yyyy" and "dd/mm/yyyy '. This shows also some errors, I can't found. pls help to solve this problem...

    Hello

    Christine Schnittker says:
    ... It works as well:

    SQL> select to_date('22-02-2012','dd/mm/yyyy') dt from dual;
    
    DT
    ----------
    22-02-2012
    

    (Does anyone know anything that actually says?)

    The Manual of the SQL language , after listing the format items allowed in TO_DATE, says the following:

    Any nonalphanumeric character is allowed to match punctuation characters in the format model. For example, the following statement returns no error:
    SELECT TO_CHAR (TO_DATE('02#07','MM/YY'), ' MM/YY') FROM DUAL;

    TO_CH
    -----
    02/07

Maybe you are looking for

  • Audit in two stages on the same device? !

    After upgrading to Mac OS Sierra the next thing happened: When I tried to sign in the community Apple with my Macbook Pro, I had a request of two steps and was invited to enter the 6 digit code that 'someone was trying to use my Apple ID to a place n

  • How e-mail messages do not end up in the folder "Important"?

    I never created a folder labeled 'important' so I don't know the rules on how things end up here. I'm usually confused as to why thunderbird keeps messages in a folder "all messages" when I set rules to the plot of these messages in separate folders.

  • El Capitan 10.11.3 calendar in double Exchange items

    Just updated to 10.11.3.  Using calendar for icloud and Exchange Server accounts.   iCloud works very well, but the calendar is now duplicate all the individual events of the exchange calendar.  Tried to remove the account and restart - no luck.  Tri

  • Windows Vista Ultimate Edition with HP Color LaserJet CM1015 MFP

    I'm running Windows Vista Ultimate, the computer was bought in 2008, 32-bit.  I also use HP Color LaserJet CM1015 MFP - about once a year, I have a major problem with the scan software & Windows Vista.  Both machines are in good working condition.  T

  • Missing user account from the logon screen icons

    I tried and tried to understand it, but not impossible. My 5 year old son and his friend were playing a game on the computer for a little while and when I tried to change username on my account (Administrator) the only icons that have been confirmed