How to convert JAVA.SQL.DATE date in YYYY/MM/DD format into DD/MM/YYYY

i am using informix database which accepts date value in the form of DATE format......
the other part of my application takes date from the field in DD/MM/YYYY format...so i have to convert my java.sql.date in YYYY/MM/DD fromat into DD/MM/YYYY fromat of same type before inserting into db......
but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
and also using format method can result only in string conversion........

816399 wrote:
i am using informix database which accepts date value in the form of DATE format......Huh?
Maybe you mean Informix (fronted by JDBC) expects date values as java.sql.Date objects?
the other part of my application takes date from the field in DD/MM/YYYY format...
so i have to convert my java.sql.date in YYYY/MM/DD format into DD/MM/YYYY format of same type before inserting into db......I am not sure why you are talking about formats here.
There is no formatting inherent in a java.util.Date object
nor in a java.sql.Date object.
but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
and also using format method can result only in string conversion........You can easily create a java.sql.Date object from a java.util.Date object.
String s = "31/12/2010";
java.util.Date ud = new java.text.SimpleDateFormat("dd/MM/yyyy").parse(s);
java.sql.Date sd = new java.sql.Date(ud.getTime());
ud = sd; // java.sql.Date extends java.util.Date so no conversion is needed

Similar Messages

  • How to get java.sql.Timestamp data from database

    Hello, i'm new to EJB and i can't get java.sql.Timestamp data, but when i'm trying to get java.lang.String data it works fine.
    * @ejb.finder
    * query="SELECT OBJECT(c) FROM userSCHEMA AS c
    *      WHERE c.lastName LIKE ?1
    * AND c.firstName LIKE ?2
    * AND c.registeredDate < ?3"
    * signature="java.util.Collection findPatient * (java.lang.String lastName,
    * java.lang.String firstName,
    * java.sql.Timestamp)"
    <method-params>
    <method-param>java.lang.String</method-param>
    <method-param>java.lang.String</method-param>
    <method-param>java.sql.Timestamp</method-param>
    </method-params>
    Where i made a mistake ?

    The main problem that I'm faced with, is that the
    java.sql.Timestamp now has only one constructor, it
    takes "long", i.e., milliseconds.That's because a Timestamp is just an offset from a particular instant of time. It doesn't have a timezone.
    Please note that I'm not trying to "print", i.e., I'm
    not interested in using the SimpleDateFormat.Then what are you interested in? You appear to be trying to create a Timestamp with a particular timezone, which doesn't make sense as I already noted. Is there a reason for this?

  • How to convert MS SQL Server data to XML data using Java

    Hi all!
    How do I generate XML document for SQL Server data using java / jsp.
    Thanks in advance

    http://www.fdsapi.com

  • Convert java.sql.date to dd.mm.yyyy format

    Hi,
    Can any one tell me how to convert java.sql.date to dd.mm.yyyy format
    Regards,
    H.V.Swathi

    Hi ,
    Create a simple data type of type java.sql.date and give the format in it as "dd/MM/yyyy". This will work i guess.
    Regards
    Ishita

  • How to convert Flat file(.txt) data to an Idoc format(ORDERS05)

    Hi,
    How to convert Flat file(.txt) data to an Idoc format(ORDERS05). If any FM does the same work please let me know.
    thanks in advance,
    Chand
    Moderator message : Duplicate post locked. Read forum rules before posting.
    Edited by: Vinod Kumar on Jul 26, 2011 11:11 AM

    Hi,
            For more information, please check this link.
    http://sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/46759682-0401-0010-1791-bd1972bc0b8a
    Have a look at the FM IDOC_XML_FROM_FILE. May be it helps...
    Regards

  • SetNull(2, java.sql.Types.DATE);

    If I use setNull(1, java.sql.Types.DATE); function, it will insert null on my table's column.
    I want to select the date from another table and insert into my table's column, what should I do?
    I am sure I cannot call setNull(1,java.sql.Types.DATE), it will insert NULL in my column.
    Thanks in advance.

    Hi,
    I think you will be better of in asking ths question in Java forum or Oracle Developer forum.
    Regards

  • Cannot obtain connection after 30 seconds. : java.sql.SQLException: Data So

    Hi Guys,
    I need some help, I've already set up my datasource. It was working when i had only 1 EJB module.
    But when i added another ejb module to be loaded. I started having this kind of problem:
    ##<Oct 11, 2007 9:07:17 AM GMT+08:00> <Error> <Deployer> <djao> <AdminServer> <[STANDBY] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1192064837780> <BEA-149231> <Unable to set the activation state to true for the application 'Test.ear'.
    weblogic.application.ModuleException: Exception activating module: EJBModule(MyEntityEJBs.jar)
    Unable to deploy EJB: MyEntity from MyEntityEJBs.jar:
    Cannot obtain connection after 30 seconds. : java.sql.SQLException: Data Source jdbc/DataSource does not exist.
         at weblogic.ejb.container.deployer.EJBModule.activate(EJBModule.java:422)
         at weblogic.application.internal.flow.ModuleListenerInvoker.activate(ModuleListenerInvoker.java:107)
         at weblogic.application.internal.flow.DeploymentCallbackFlow$2.next(DeploymentCallbackFlow.java:381)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.activate(DeploymentCallbackFlow.java:71)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.activate(DeploymentCallbackFlow.java:63)
         at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:641)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:229)
         at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:154)
         at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)
         at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:181)
         at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:352)
         at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:52)
         at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:186)
         at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)
         at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:233)
         at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)
         at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)
         at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:173)
         at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:89)
         at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
         at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    Cannot obtain connection after 30 seconds. : java.sql.SQLException: Data Source jdbc/DataSource does not exist. NestedException Message is :Cannot obtain connection after 30 seconds. : java.sql.SQLException: Data Source jdbc/DataSource does not exist.
         at weblogic.ejb.container.cmp11.rdbms.PersistenceManagerImpl.verifyDatabaseType(PersistenceManagerImpl.java:251)
         at weblogic.ejb.container.cmp11.rdbms.PersistenceManagerImpl.setup(PersistenceManagerImpl.java:148)
         at weblogic.ejb.container.manager.BaseEntityManager.setupPM(BaseEntityManager.java:295)
         at weblogic.ejb.container.manager.BaseEntityManager.setup(BaseEntityManager.java:244)
         at weblogic.ejb.container.manager.DBManager.setup(DBManager.java:172)
         at weblogic.ejb.container.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:1379)
         at weblogic.ejb.container.deployer.EntityBeanInfoImpl.activate(EntityBeanInfoImpl.java:232)
         at weblogic.ejb.container.deployer.EJBDeployer.activate(EJBDeployer.java:1270)
         at weblogic.ejb.container.deployer.EJBModule.activate(EJBModule.java:405)
         at weblogic.application.internal.flow.ModuleListenerInvoker.activate(ModuleListenerInvoker.java:107)
         at weblogic.application.internal.flow.DeploymentCallbackFlow$2.next(DeploymentCallbackFlow.java:381)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.activate(DeploymentCallbackFlow.java:71)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.activate(DeploymentCallbackFlow.java:63)
         at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:641)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:229)
         at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:154)
         at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)
         at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:181)
         at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:352)
         at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:52)
         at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:186)
         at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)
         at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:233)
         at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)
         at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)
         at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:173)
         at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:89)
         at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
         at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    Can anyone help me with this pls? Im sure that my datasource exist, I could even test the connection in the admin console.
    Daniel

    Are you sure you have your datasource in place? You can test connection pools, but not datasources.

  • Convert java.sql.Timestamp to java.util.Calendar?

    What's the best way to convert java.sql.Timestamp to java.util.Calendar?

    Use Calendar's setTime(Date date) method.
    java.sql.Timestamp extends java.util.Date.
    -Roy

  • How to update java.sql.Clob using javax.persistence.EntityManager?

    Hello.
    Can anyone tell me (or show me some example) how to update java.sql.Clob using javax.persistence.EntityManager.
    When I’m trying to update column (with type Clob) value is not inserting, after update column is empty. I haven’t any error during update, I’m using database Oracle 10g.
    Edited by: ernest211 on Jul 16, 2009 1:24 AM

    Post some code so we can see how you are doing it. If you are using JPA entities take a look at the @Lob annotation.
    m

  • How to convert Java Objects into xml?

    Hello Java Gurus
    how to convert Java Objects into xml? i heard xstream can be use for that but i am looking something which is good in performance.
    really need your help guys.
    thanks in advance.

    There are apparently a variety of Java/XML bindings. Try Google.
    And don't be so demanding.

  • In fact it's about mac:excel, how convert in a cell a number written in text format into a value?

    in fact it's about mac:excel8 or 11 in OSX10.7.4,
    how convert in a cell a number written in text format into its value?
    cheers francois

    Hi francois,
    If I copyone of them and do a past special/value, it does not work.
    Try just Paste instead of Paste Special > Value
    I know your question is about Excel, but this works in Numbers:
    Copy 1 234 567 (with spaces) and Paste (not Paste Special) into a Cell in a Numbers Table. The result is 1234567 and it behaves as a number. A formula will consider it to be a number:
    You asked Wayne: what do you mean by "to reference a cell" ??
    The reference is from Cell A2 to Cell A1 through a formula, such as: =A1+1
    Regards,
    Ian.

  • How to use java.sql.Date ?

    hi there:
    I used
    ps.setDate(27, new java.sql.Date(new java.util.Date().getTime()));
    ps.executeUpdate();
    in my code to insert the current date to the 27th column of one table, this column's type is DATE, the database is ORACLE. However, I got the error like this one: ORA-01843: not a valid month.
    I think I incorrectly used the java.sql.Date API to cause this error. So anyone can tell me how to use it correctly?
    Thanks for the answers,
    Sway

    Other columns are all VARCHAR2 type;
    The oracle error message indicated that this is a
    date-related one. 27th are the only column using DATE
    So I came to draw my conclusion that the SQL might be
    wrong.Except that if, for example, the date column is actually at index 26 then Oracle might try to convert the string being passed in (at 26) as a date. But it isn't a date. So then oracle is going to throw an exception indicating that something is wrong - like that the month is invalid.

  • Convert java.sql.Date to java.util.Date

    How do i convert a java.sql.Date to java.util.Date ?
    SimpleDateFormat formatter = new SimpleDateFormat ("dd/MM/yy HH:mm");
    Date received=myresultset.getDate(1);
    String utildate = formatter.format(received);
    <%=utildate%>
    Result : doesn't keep the HH:mm format
    14/03/04 00:00
    Ideas ?

    There is simple way to do this job...
    java.util.Date utilDate = new java.util.Date();
    java.sql.Data sqlDate = new java.sql.Date(utilDate.getTime())
    Enjoy Coding ! ! ! ! !

  • How do I return a java.sql.Timestamp data type in a Web service?

    I'm new to workshop and java. I'm creating a mini application to simulate a real work Web Service (development environment is on an intranet). I was able to completely simulate the Web Services minus all date values.
    I'm using a standard weblogic workshop database controls that are feeding the various WebServices and their methods (Web services was generated from DB control). I get a java type not support error when I attempt to return a java.sql.Timestamp. I temporarily got around the problem by omitting all dates from the sql.
    However, we are at the point where we need the complete record.
    My two questions
    1) What java data type do I convert the java.sql.Timestamp to
    2) Where and how do I do it in workshop.
    Thanks in advance
    Derrick
    Source view from workshop looks something like this.
    public interface MyData extends DatabaseControl, com.bea.control.ControlExtension
    static public class dbOverallRec
    public String key;
    public String field1;
    public int field2;
    public java.sql.Timestamp create_date
    public dbOverallRec () {};
    *@jc:sq; rowset-name="OverallRowSet" statement::
    *select key, field1, field2 ,create_date from overall where key={KEY}::
    dbOverallRec getOverallByKey(String Key);
    * I had to omit the create_date to get it to work

    You should try changing java.sql.Timestamp to java.util.Calendar.
    java.util.Calendar maps to the dateTime type in XML Schema, and TIMESTAMP as a JDBC type.
    Regards,
    Mike Wooten

  • Convert java.sql.Date to oracle.jbo.domain.Date in oaf

    Hi,
    Need to dafault NeedBydate(i get in from query as below) to a messagelovinput and make it read only.
    i am facing some issue in converting from java.sql.Date to oracle.jbo.domain.Date.
    unable to figure out the problem.
    below is the sample code im trying to use.
    PreparedStatement ps=pageContext.createPreparedStatement("select sysdate from dual");
    ResultSet rs=ps.executeQuery();
    if (rs!=null && ps.next()
    java.sql.Date sqlDate= rs.getDate(1);
    oracle.jbo.domain.Date oracleDate = new oracle.jbo.domain.Date(sqlDate.getTime());
    vorow.setAttribute("Datevalue",oracleDate);
    this is my assumption : to set to UI i need date in format dd-Mon-yyyy.(am i correct? as to get that format i tried to use simple date format class but no use)
    when i tried to use simple date format :unpaseable date exception was raised.
    please guide.

    Hi,
    Why are you using this code???
    PreparedStatement ps=pageContext.createPreparedStatement("select sysdate from dual");
    ResultSet rs=ps.executeQuery();
    if (rs!=null && ps.next()
    java.sql.Date sqlDate= rs.getDate(1);
    oracle.jbo.domain.Date oracleDate = new oracle.jbo.domain.Date(sqlDate.getTime());
    you can get sysdate using this and then set it
    oracle.jbo.domain.Date currentDate = am.getOADBTransaction().getCurrentUserDate();
    java.text.SimpleDateFormat displayDateFormat = new java.text.SimpleDateFormat ("yyyy-MM-dd");
    String DateForm = displayDateFormat.format(currentDate.dateValue());
    oracle.jbo.domain.Date dateset = new oracle.jbo.domain.Date(DateForm);
    and then set the attribute
    vorow.setAttribute("Datevalue",dateset);
    Thanks,
    Gaurav

Maybe you are looking for

  • How can I set Firefox to open a new page each time it starts

    I need to be able to start automatically a new page when Firefox start. I have my home page setup but I'd like to start a new url in a new window each time Firefox is started. Thanks

  • Have working PL/SQL, need to create a PDF

    I am a newbie to Oracle Reports, and I need to generate a report that is beyond the basic reports scenario. I am having no luck with the GUI or web editor (I can't even get anchors and expandable sections to work), but I have a working PL/SQL routine

  • Problem with Zen X-FI - MTP - Please help =P

    ,? My MP3 player worked perfectly fine on my computer before reformatting. Now, I keep getting an MTP installation error when I install it. My computer registers the player as a MTP device but keeps saying that there's an error with the installation

  • HT5834 Keychain Request

    HHelp  broken flat on my back. Apple trying to send code to landline. Can't get to Air or Bigmac. What do I do? Obviously I havey keychain pswd or I would not be on this form. SUggestions? tired of only access iphone  - on week 8 of 16 of this..... C

  • It still won't convert a simple .doc file

    Hello, I've been desperately trying to convert a 94 page .doc file into .pdf by uploading it using my monthly subscription "Create Adobe PDF Online". However, I've tried numerous times and I always get an email that states: "Conversion for this docum