Insert current date and time into Oracle date type field

I have a JDBC current date and time insert into Oracle 9i that almost works. It submits the current date and a fixed time into the Oracle date type field. I am using Tomcat 6.0.20.
For example if I insert the data at 7:24:04 PM on Feb 16, 2010 it will insert as: 16-Feb-2010 12:00:00 AM
The date part works but the time always shows 12:00:00 AM no matter what date or time the data is inserted.
Here is what I have for my JDBC inserts and I also tried something with DateFormat:
PreparedStatement ps; Date mydate = new Date(new java.util.Date().getTime()); //insert statement here.... stmt.setDate(1,mydate);
I also tried:
PreparedStatement ps; java.sql.Timestamp mydate = new java.sql.Timestamp(new java.util.Date().getTime()); SimpleDateFormat fmt = new SimpleDateFormat(.... //insert statement here.... ps.setTimestamp(1,fmt.format(mydate));
Both keep submitting the date into Oracle as 16-Feb-2010 12:00:00 AM
Anyway to get the current date and time? For example if I insert the data at 7:24.04 pm today it should show as 16-Feb-2010 07:24.04 PM in Oracle.

sportsMarkr wrote:
Date mydate = new Date(new java.util.Date().getTime());Please see the javadocs for java.sql.Date and note the part that says "...to zero"
[http://java.sun.com/javase/6/docs/api/java/sql/Date.html]
If you want a date and time then use java.sql.Timestamp.

Similar Messages

  • Inserting current pathname and filename into Pages documents?????

    Pages help explicitly says you can put "filenames" and "pathnames" into formatted text fields just as you can put in page numbers and the date. It does NOT tell you how to do this!!! What do I type so that my current pathname appears in pages? Or the current filename of my document?? I am trying to create a template so that filename, pathname, date, and number of pages always appears in the header.

    Well, it is possible to automatically insert the document's filename into the header as I routinely do it in (dare I say) Microsoft Word and Microsoft Excel. I write many documents long and short. For each of them I start with the same template, one that includes the filename and the date "last saved" in the header.
    Those who have an ironclad hierarchy where every file is unambiguously filed into one folder might easily be able to retrieve every file. For me, it is very useful to know the filename of the document I am searching for (as it is on my hardcopy) and to know that it is "sept-mon-rpt-final" and not "sept-mon-rpt-mikes-edits". As my example suggests, the greatest utility of this is for version control.
    I do not want to type my filename into every draft document, I want them to insert themselves in the header in the same manner that Pages inserts the current date. This information, filename and pathname, is in the Mac system. Indeed, there is a reference to it in the Pages documentation.
    In Pages'08 Help - the page titled: "Working with Document Parts" under "using Headers and Footers" it says, "Add headers and footers to give your documents page-by-page identity by showing the date and time, page number, or filename and pathname."
    When you click on the link that says "Using Headers and Footers" you are taken to that page, where it says, "you can put your own text or graphics in a header or footer, and you can use formatted text fields. Formatted text fields allow you to insert text that is automatically updated. For example, inserting the date field shows the current date whenever you open the document. Similarly, page number fields keep track of page numbers as you add or delete pages."
    After this you hit a dead end.

  • Inserting Date and Time into a date field

    Okay I am a bit of a Oracle newbie. I am trying to insert the following date and time into a date field and I don't know how to format the second part of the to_Date() function.
    Date/Time: 5/29/2003 7:58:45 PM
    Thanks,
    Branden

    I believe you would want
    to_date( '5/29/2003 7:58:45 PM', 'MM/DD/YYYY HH:MI:SS AM' )
    Note that tahiti.oracle.com has all of Oracle's documentation, including the very useful SQL & PL/SQL reference manuals, available for free.
    Justin

  • As of version 31, why is there still no Thunderbird option to insert current date and time in message that you are writing?

    As of version 31, why is there still no Thunderbird option to QUICKLY insert current date and time in message that you are writing?
    Literally have seen this very-much-needed -- and used -- option "promised" for three years now, and even if there's only one or two formats that could be used, at least the option is there.
    It seems only way is to link a Macro and tool to Thunderbird and do it that way.
    Joe Rotello
    [email protected]
    Skype: joerotello

    Where was it promised? A quick search of Bugzilla didn't find a functionality request bug report for it.
    I assume you're aware that Mozilla stopped development about 2 years ago (just adds security/stability fixes and provides infrastructure) and all new features and bug fixes are now added by the community. They seem pretty tied up with bug fixes and reworking some hard to maintain components such as the MIME support.
    Have you tried the Timestamp add-on at https://addons.mozilla.org/en-us/thunderbird/addon/timestamp/ ? The version at AMO doesn't support versions later than 2.0 so you'd need to do something like install the disable add-on compatibility checks add-on at https://addons.mozilla.org/en-us/thunderbird/addon/checkcompatibility/?src=ss, and ignore the warning message about Timestamp not being compatible. However, the author has a version at http://extensions.sanjer.nl/?page=tb_ts that supposedly supports up to Thunderbird 11.9.x so it should be "compatible by default as it supports version 5 or later and is not a binary add-on like Lightning or Enigmail.
    "For Thunderbird use the context menu (right click popup) in the compose window, Ctrl+Shift+T or "Options | Insert timestamp" to inserts the date/time into a message"

  • Problem with getting current date and time using oracle.jbo.domain.Date

    I`d like to get current date and time using oracle.jbo.domain.Date method getCurrentDate(), but it always return current date and 12:00:00. I also need to get the current time.

    I think you should use java.sql.Timestamp domain.
    (And set database type to TIME or DATETIME.)
    Jan

  • Insert current date/time problem in ViewObject

    Hi!
    I'm trying to setAttribute to a Date type field.
    I have a method:
    public String getCurrDateString() throws ParseException, java.sql.SQLException {
    SimpleDateFormat formatter = new SimpleDateFormat ("dd-MMM-yyyy hh:mm:ss aa");
    Date currentTime_1 = new Date();
    return formatter.format(currentTime_1);
    All the time i call this method such as:
    HistoryViewImpl histVO=getHistoryView();
    Row r=histVO.createRow();
    r.setAttribute("Entrydatetime",cp.getCurrDateString());
    I get oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:oracle.jbo.domain.Date with value:19-Jun-2002 10:14:33 AM
    the strange thing is, that Oracle recognizes this kind of format, because if I use different pattern such as "yyyy-MM-dd", which returns string "2002-06-19", r.setAttribute("Entrydatetime",cp.getCurrDateString()) method works fine and in Oracle table field we have inserted value 19-Jun-2002 12:00:00 PM. The problem is, that i don't need 12:00:00 PM as a time, i need current time.
    What am i doing wrong? Or does it mean that oracle.jbo.domain.Date doesn't know format "dd-MMM-yyyy hh:mm:ss aa"?

    Hi!
    I'm trying to setAttribute to a Date type field.
    I have a method:
    public String getCurrDateString() throws ParseException, java.sql.SQLException {
    SimpleDateFormat formatter = new SimpleDateFormat ("dd-MMM-yyyy hh:mm:ss aa");
    Date currentTime_1 = new Date();
    return formatter.format(currentTime_1);
    All the time i call this method such as:
    HistoryViewImpl histVO=getHistoryView();
    Row r=histVO.createRow();
    r.setAttribute("Entrydatetime",cp.getCurrDateString());Instead of passing in the "String" pass the date object as is. oracle.jbo.domain.Date should be able to convert java.sql.Date/Time/Timestamp and store the time bits as set.
    If you have to pass in string, then establish a Formatter on the attribute with appropriate date format and then use the AttributeHints interface from the relevant AttributeDef object on the row to parse the input String into a valid parsed object that you can set into the row.
    (See oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow() method for a complete usage - source in bc4j\src\bc4juisrc.zip)
    I get oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:oracle.jbo.domain.Date with value:19-Jun-2002 10:14:33 AM
    the strange thing is, that Oracle recognizes this kind of format, because if I use different pattern such as "yyyy-MM-dd", which returns string "2002-06-19", r.setAttribute("Entrydatetime",cp.getCurrDateString()) method works fine and in Oracle table field we have inserted value 19-Jun-2002 12:00:00 PM. The problem is, that i don't need 12:00:00 PM as a time, i need current time.
    What am i doing wrong? Or does it mean that oracle.jbo.domain.Date doesn't know format "dd-MMM-yyyy hh:mm:ss aa"?

  • Extract the data from SQL Server and Import into Oracle

    Hi,
    I would like to run a daily job that will export the table data from SQL server table (it will be only one or two table) and Import back into Oracle table (it might one or two table tables).
    Could you please guide me that how can i do this using either sql server or oracle?
    We have oracle 9.2 and sql server 2005.
    Normally i do from flat file which is generated by source destination nand i dump into oracle using sql*loader but this time I have to directly extract/export the data from MS Sql server and load into Oracle table, mostly it will reload so i might doing any massaging data during the load.
    If you show me the detail approach, it will be really appreciated.
    I have access to Sql server but i don't how to use sql server to do this or using oracle as a daily job even becuase have to schedule the job for this as it will be a daily job.
    Thanks,
    poratips

    Unless you can find an open source ODBC driver for SQL Server that runs on Solaris (and I wouldn't be overly hopeful there) Heterogeneous Services would require that you license something-- a third party ODBC driver, a new Oracle instance, or an Oracle Transparent Gateway.
    As I stated below, you could certainly use SQL Server's ETL tool, DTS. Oracle's ETL tools would require additional licensing since you're just on 9.2. You could also write a small application (Java or otherwise) that connected to both databases and transferred the data. If you're particularly enterprising, you could load the SQL Server Type 4 JDBC driver into Oracle's JVM and write a Java stored procedure that connected to the SQL Server database via JDBC, but that's a pretty convoluted approach.
    Justin

  • Combining Date and Time into 1 Field

    Post Author: Marc Vaccarino
    CA Forum: Formula
    Hi,
    I'm trying to write a formula to combine 2 fields (date and time) into one. I would like it to look like this.
    2/12/2007 + 12:00pm = 2/12/2007 12:00pm
    Thanks,

    Post Author: Marc Vaccarino
    CA Forum: Formula
    Thanks that worked but my problem is currently the date field I'm using has a date and time (12/12/2007 12:00am) and the time field has it as well  (12/12/2007 1:45am).  I've been going into crystal and clicked on format field and just showing the date and in the time field, just showing time. Then I would extract the report to excel then run another formula to get it to work. I'm looking to automate it a little. Any ideas??

  • Read data from Excel and write into oracle database

    Hi
    I want  to know how can i read data from excel and write into oracle database using java.Kindly help me out to find a solution.
    Thanks and Regards
    Neeta

    Hai,
    I am suggesting the solution.
    I will try out and let u know soon.
    Make a coma separated file from your excel file.
    Assuming that your requirement allows to make a csv file.
    This file may be passed as an file object to be read by java.Using JDBC you must be able to populate the data base.You can also use String Tokenizer if needed.
    You do not want to  go via sql Loader?
    For reading the excel file itself do you want java?

  • Insert Current Date into text Field

    Hi I was wondering if anyone knows how to insert the current
    date into a text field using ASP.NET C# page. When the page loads.
    Or better still insert current date into my database when the
    page is updated. using the insert Server behavier.
    I would be very greatfull for any help.

    To assign it to a text box you couls use the following in the
    onload
    function
    textbox.Text = DateTime.Now.toString;
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver
    Valleybiz Internet Design
    www.valleybiz.net
    "cantmakeitwork" <[email protected]> wrote
    in message
    news:e9qhrv$crd$[email protected]..
    > Hi I was wondering if anyone knows how to insert the
    current date into a
    > text
    > field using ASP.NET C# page. When the page loads.
    >
    > Or better still insert current date into my database
    when the page is
    > updated.
    > using the insert Server behavier.
    >
    > I would be very greatfull for any help.
    >

  • Please help! Looking for script to insert current date on page.

    I currently use a Dreamweaver Extension that lets you insert
    current date and time on your web page.
    The problem is, I don't know Javascript and cannot edit the
    Javascript codes to "remove the time"
    I only need the current date that will change every day.
    Do you know where I can get this script, I goggled and got
    several but I'm looking for something authentic.
    Also is it possible to have your page validate when you use
    Javascript embedded in your HTML?
    Thanks everyone,
    Patrick

    quote:
    Originally posted by:
    Newsgroup User
    Webethics wrote:
    > The problem is, I don't know Javascript and cannot edit
    the Javascript codes
    > to "remove the time"
    > I only need the current date that will change every day.
    JavaScript generates the date by using the clock on the
    computer of each
    visitor to your site. If a visitor's clock has the wrong
    date, your site
    will also display the wrong date.
    > Do you know where I can get this script, I goggled and
    got several but I'm
    > looking for something authentic.
    I don't know what you mean by "authentic". Date generation in
    JavaScript
    is one of the most basic features of the language, so if it
    works, it's
    "authentic".
    > Also is it possible to have your page validate when you
    use Javascript
    > embedded in your HTML?
    Yes, but you shouldn't embed JavaScript in XHTML.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/
    So mr. Powers are there people that use Javascript Date in
    their page?
    Would you recommend it?
    I could use PHP but I don't know PHP,
    How do I come up with the string in this format, say,
    Wednesday, October 29th, 2008 that will change to a new day
    according to the server time and date.
    Thanks so much for your help and I have two of your books! I
    will be taking PHP classes in December.
    Patrick

  • INSERT/UPDATE date type

    I'm using an Oracle 816 and Java 2.
    There is no problem with retrieving data from the tables. My problem is "INSERT date".
    Code snip:
    (java.util.)Date dtToday = new Date();
    String strSQL = "INSERT INTO MY_DB.TABLE1 " +
    "(COLUMN1, COLUMN2) VALUES (\"bluh\", " +
    dtToday + ")";
    myStmt.executeUpdate(strSQL);
    Would you please tell me what is the right way to insert a date type (any from java.util.Date, java.sql.Date, or oracle..DATE) to an Oracle 816 table that has a date column.
    Thank you very much in advance.
    Robin Luo

    Try to use prepared statement:
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into TABLE1(COLUMN1, COLUMN2) values (?, ?)");
    pstmt.setString (1, "bluh");
    pstmt.setDate (2, dtToday);
    pstmt.execute ();
    null

  • To find the date type fields in the row and validate those date fields

    TYPES : BEGIN OF TY_MARA,
              MATNR TYPE MARA-MATNR,
              ERSDA TYPE MARA-ERSDA,
              ERNAM TYPE MARA-ERNAM,
              LAEDA TYPE MARA-LAEDA,
              MTART TYPE MARA-MTART,
            END OF TY_MARA.
    DATA : it_mara TYPE STANDARD TABLE OF ty_mara,
          it_mara1 TYPE STANDARD TABLE OF ty_mara,
           wa_mara TYPE ty_mara.
    loop at it_mara into wa_mara.
      describe field wa_mara-ersda type c_data.
    if c_data eq 'D'.
      CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
        EXPORTING
          date                            = wa_mara-ersda
       EXCEPTIONS
         PLAUSIBILITY_CHECK_FAILED       = 1
         OTHERS                          = 2
      IF sy-subrc eq 0.
    wa_mara-ersda = '00000000'.
        append wa_mara to it_mara1.
        write :wa_mara-matnr,wa_mara-ersda.
        else.
            wa_mara-ersda = '00000000'.
        append wa_mara to it_mara1.
        write :wa_mara-matnr,wa_mara-ersda.
      ENDIF.
      endif.
      endloop.
    This issue regarding how to find the date type fields in the row and validate those date fields.If its not a valid date ,i have to assign initial value to that.
    I've tried that for single field using describe field.Please help me do that for all fields.

    Hi Sam,
     I believe we had discussed the same issue in the below thread. Can you please refer the below one?
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/d93e16ff-c123-4b36-b60b-60ccd34f6ca7/calculate-time-differences-in-infopath?forum=sharepointcustomizationprevious
    If it's not helping you please let us know
    Sekar - Our life is short, so help others to grow
    Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever
    you see a reply being an answer to the question of the thread, click "Mark As Answer

  • How to Update Date data type field value in oracle

    I want to update records in a table that has a Date data type field. It's a oracle databse. I use the oracle thin drive to connect to the database. The everything works well, only when i try to update records that have date type value, something doesn't work.
    I use the following stmt to update DB:
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Conn = DriverManager.getConnection("jdbc:oracle:thin:@hostname:portnumber:schname", "uid","pwd");
    stmt=Conn.createStatement();
    String updStr = "UPDATE Article SET Archive = ' Disable' WHERE ArticleDate = # " + sqlDate +"# " ;
    stmt.executeUpdate( updAStr ) ;
    But I always got the SQLException run time error, which is "ORA-00911: invalid character"
    Who can help me to find out how to write the above Update statement correctly? esp. that how to present the Date type variable in the statement.!
    BTW, sqlDate is a Java.sql.Date variable, Is it "# " + sqlDate + "# " the right way?
    Many thanks

    What do you get out of Oracle's TO_DATE that java.sql.PreparedStatement.setDate()
    won't give you? - MODWell, I don't know that I've used all capabilities of either, but when it comes to managing Date Strings my Oracle bias :) would be to code using Oracle's TO_CHAR and TO_DATE functions. Perhaps someone can tell me vendor neutral ways to do something simiilar to managing these input date/times (and hopefully just as easily, pretty much all done in a single line, single function)?
    WHERE aDATE > TO_DATE('2010','YYYY')
    WHERE aDATE > TO_DATE('2010 AUG 22','YYYY MMM DD')
    WHERE aDATE > TO_DATE( 'January 15, 1989, 11:00 A.M.', 'Month dd, YYYY, HH:MI A.M.')
    I believe most databases have something similar to this, although I have found Oracle's to be the most flexible and consistent, if not the most intuitive. Other vendors (DB2, SQL Server, Access) don't force you to always be explicit, and can accept a variety of date strings without masks. The problem is that while you might not be getting an error, it also may not be parsing your date as expected.
    One could argue that this vendor specific hodgepodge of literal date/time strings is only one program modification away from disaster. They might be right.
    Just to be clear. I'm not recommending using a vendor specific approach, but it's not a perfect world and somtimes you have to use what works easiest or best or fastest, and in some cases, that is the vendor specific alternatives.

  • Importing an SQL Server TEXT data type field in Oracle - problem with LONG

    Hello,
    I work in Oracle 9i and I created a view on a distant SQL Server database that contains a TEXT data type field. But I have a problem when I select that field in Oracle; I have the following error message: "ORA-00997: forbidden use of LONG data type".
    Could anybody have a solution for me, to solve that problem?
    Thanks a lot!

    It is very difficult to suggest anything without seeing your code.  I don't even know if what you are seeing is the actual value or an error code.  Often, negative numbers are indicative of error codes. 
    For instance -1 could mean that you have an invalid reference or path, etc...
    Can you post your code?

Maybe you are looking for