Saving date & time in DataBase

Hi All,
I want to save Date & Time in Database.
But only Date is saving in Database but time is not saving in Databse.
In my entity i am mapping my databse date column as,
@Column(name = "LAST_UPDATE_DATE")
@Temporal(TemporalType.DATE)
private Date lastUpdateDate;
I have imported java.util pakage in my entity.
In my java class I am setting date as,
Class ABC{
public void sample(){
Object.setLastUpdateDate(new Date());
But its saving only date not the time.
Then How to set the time here in Database.
Please help.
Thanks
Sandip

To persist both date and time you should use a java.sql.Timestamp or java.util.Calendar along with a TemporalType of TIMESTAMP:
@Temporal(TemporalType.TIMESTAMP)
private java.util.Timestamp lastUpdateDate;--Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Saving dates in the database

    How do I save a date in the database?
    My code is as follows:
    int year = 2002;
    int month = 2;
    int day = 3;
    java.util.Date sdate = new java.util.Date(year, month, day);
    PreparedStatement ps = "INSERT INTO period_table(pe_start) VALUES (?)";
    ps.setDate(1, sdate);
    ps.executeUpdate();

    To insert a Date into a database the best way is to use
    the java.sql.Date object instead of the java.util.Date
    int year = 2002;
    int month = 2;
    int day = 3;
    java.util.Date sdate = new java.util.Date(year, month, day);
    java.sql.Date sqldate = new java.sql.Date(sdate.getTime());
    Write the sqldate variable into the database.

  • How to insert a data&time to Database date field

    Dear Friends,
    I have created a Stored Procedure which takes a Date data type as an input,When i call this procedure from java i need to set the data&time in
    yyyymmddhhmmss format. How to set this from java ?.
    Rgds
    Mohan S

    How to set this from java ?.Usually you use a prepared statement and one of the set methods.
    Or you can use setString() and format the date yourself using SimpleDateFormat.

  • Saving data in sql database

    Ive seen same title subjects but apparently these topics have been deleted. Anyway,
    I have a data base named "TestDB", under url www.mysql.com/TestDB. I did in it 2 fields, "ProjectNr", "ProjectName".
    Now, I have Webdyn Pro app with two InputFields binded to Contexts "ProjectNr", "ProjectName" and a button "Save"
    What code do I need to write in onActionSave() part to make data written into those two fields be saved in sql database after pressing Save button.

    Hi,
    Following is the code, pl aligh that to your requirement
    try {
              Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
               String url="jdbc:sapdb://<HostID>/J2E?sqlmode=ORACLE";
                Connection con=DriverManager.getConnection(url,"UserID","password");
                String projectID = wdContext.current<Yournode>Element().get<yourAttribute>();
                String projectName = wdContext.current<YourNode>Element().get<your Attribute>();
                String sql = "insert into Project values (?,?)";
                PreparedStatement stmt = con.prepareStatement(sql);
                stmt.setString(1, projectID);
                stmt.setString(1, projectName);
         } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
    try to make use of JNDI for database connections. That s one of the best practises.
    http://java.sun.com/javase/technologies/database/
    Regards
    Ayyapparaj

  • Saving data in a database and publishing data to multiple clients

    Hi there.  I'm using a bunch of Compact FieldPoint modules to read out a few hundred voltages, temperatures, currents, etc.  I acquire this data at about 1 Hz (pretty slow).  I would like to record this data to some sort of database on a cpu (running LV 8.0, connected to the FieldPoint mods), and serve the data to multiple (between 10 and 50) clients over the net, each running a compiled stand-alone "data grabber and viewer" application (which I'll have to write of course).  I'd like these external clients to basically be able to pick a certain variable from the database, and plot it for the last week (or something like that).  Presumably the standalone client would send some database query to the server.  The server would then send the data to the client, and the standalone client would receive the data and plot it as the user sees fit.  My question is how to implement this database?  Should I use the LabView "Database" Add-On to create a database to store the data? Is it better to just store the data as binary and write my own data fetching routine to handle queries?  How can I write this database to disk for permanent storage? Could this database be accessible outside of LabView?
    Any help on this would be appreciated.  Thanks!
    Jesse Wodin
    Post Doctoral Researcher
    Stanford Linear Accelerator Center
    650-504-2512

    Hi Jesse,
      The Citadel database is not a relational database.  It's highly optimized for storing lower-rate (non-waveform) channel-by-channel, or "trace" measurement data.  Another option you can consider is using DSC and Citadel on the server then writing a utility to export the data from Citdael to an SQL database.  --That would solve the problem of having to write a logger application from scratch.  You would only have to write the relatively simple application to export the data from Citadel and import it into a relational database.
      You could accomplish this two ways.  First, DSC includes a set of VIs that will retrieve historical data from Ciatdel.  You could use LabVIEW to parse this data and write it to a table in a relational database.  Second, Citadel actually includes a locally accessible ODBC interface.  (You can query Citadel using an SQL query from the local computer).  You could query Citadel using this interface, then write the result to a table in a relational database.
      To view Citadel in its native format or query a Citadel database using ODBC from a remote comptuer that comptuer would need to have a licensed DSC RTS installed.
    ~~

  • Location of oracle database crash date time

    Hi,
    After system crash happens and oracle database is recovered from system crash where can i find the entry in oracle which shows the time of system crash?
    I tried the following to get the system crash date and time:
    When i start auditing a user by logon and the user is logged on to system oracle creates an entry in dba_audit_session table for user logontime in TIMESTAMP column, but if the system crashes in between when the user is logged in to the system then no entry is made in LOGOFF_TIME column of dba_audit_session table.
    in followin example orcl user is being audited by logon.
    orcl logsin the system at time 11:36 am and my system crashes.
    when orcl logsin again after instance recovery logoff_time is blank, and shows a new entry of orcl.
    SQL > select username,to_char(timestamp,'dd-mm-yyyy hh:mi:ss'),to_char(logoff_time,'dd-mm-yyyy hh:mi:ss') from dba_audit_session where username like 'TMS' order by timestamp;
    USERNAME TO_CHAR(TIMESTAMP,' TO_CHAR(LOGOFF_TIME
    ORCL 16-10-2012 11:36:16
    ORCL 16-10-2012 11:46:33
    My aim is to get the date & time of database crash.

    Hi;
    As mention here the only way to check alert.log, If Asm avaliable you need also check asmlog and related log files.
    If you have OSwatcher on your system you can also check what process or wha happend on your server too
    PS:Please dont forget to change thread status to answered if it possible when u belive your thread has been answered, it pretend to lose time of other forums user while they are searching open question which is not answered,thanks for understanding
    Regard
    Helios

  • Saving data in database using textbox and save button

    Hello. I just want a help about my code because when i close the application the data that i add is not been saved.
    Here is my code of save:
    function saveData(event:MouseEvent):void
      status.text = "Saving data";
      insertStmt = new SQLStatement();
      insertStmt.sqlConnection = conn;
      var sql:String = "INSERT INTO employees (firstName, lastName, salary) VALUES (:param, :param1, :param2)";
      insertStmt.text = sql;
      insertStmt.parameters[":param"] = firstName.text;
      insertStmt.parameters[":param1"] = lastName.text;
      insertStmt.parameters[":param2"] = salary.text;
      insertStmt.addEventListener(SQLEvent.RESULT, insertResult);
      insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);
      insertStmt.execute();
    Here is the full code:
    import fl.data.DataProvider;
    import flash.data.SQLResult;
    import flash.data.SQLConnection;
    import flash.filesystem.File;
    import flash.data.SQLStatement;
    import flash.data.SQLConnection;
    var conn:SQLConnection;
    var createStmt:SQLStatement;
    var insertStmt:SQLStatement;
    var insertStmt2:SQLStatement;
    var insertStmt3:SQLStatement;
    var selectStmt:SQLStatement;
    var insert1Complete:Boolean = false;
    var insert2Complete:Boolean = false;
    saveBtn.addEventListener(MouseEvent.CLICK, saveData);
    loadBtn.addEventListener(MouseEvent.CLICK, getData);
    init();
    function init():void
      conn = new SQLConnection();
      conn.addEventListener(SQLEvent.OPEN, openSuccess);
      conn.addEventListener(SQLErrorEvent.ERROR, openFailure);
      status.text = "Creating and opening database";
      // Use these two lines for an on-disk database
      // but be aware that the second time you run the app you'll get errors from
      // creating duplicate records.
    // var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");
    // conn.openAsync(dbFile);
      // Use this line for an in-memory database
      conn.openAsync(null);
    function openSuccess(event:SQLEvent):void
      conn.removeEventListener(SQLEvent.OPEN, openSuccess);
      conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);
      createTable();
    function openFailure(event:SQLErrorEvent):void
      conn.removeEventListener(SQLEvent.OPEN, openSuccess);
      conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);
      status.text = "Error opening database";
      trace("event.error.message:", event.error.message);
      trace("event.error.details:", event.error.details);
    function createTable():void
      status.text = "Creating table";
      createStmt = new SQLStatement();
      createStmt.sqlConnection = conn;
      var sql:String = "";
      sql += "CREATE TABLE IF NOT EXISTS employees (";
      sql += " empId INTEGER PRIMARY KEY AUTOINCREMENT,";
      sql += " firstName TEXT,";
      sql += " lastName TEXT,";
      sql += " salary NUMERIC CHECK (salary >= 0) DEFAULT 0";
      sql += ")";
      createStmt.text = sql;
      createStmt.addEventListener(SQLEvent.RESULT, createResult);
      createStmt.addEventListener(SQLErrorEvent.ERROR, createError);
      createStmt.execute();
    function createResult(event:SQLEvent):void
      createStmt.removeEventListener(SQLEvent.RESULT, createResult);
      createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);
      addData();
    function createError(event:SQLErrorEvent):void
      status.text = "Error creating table";
      createStmt.removeEventListener(SQLEvent.RESULT, createResult);
      createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);
      trace("CREATE TABLE error:", event.error);
      trace("event.error.message:", event.error.message);
      trace("event.error.details:", event.error.details);
    function addData():void
      status.text = "Adding data to table";
      insertStmt = new SQLStatement();
      insertStmt.sqlConnection = conn;
      var sql:String = "";
      sql += "INSERT INTO employees (firstName, lastName, salary) ";
      sql += "VALUES ('Bob', 'Smith', 8000)";
      insertStmt.text = sql;
      insertStmt.addEventListener(SQLEvent.RESULT, insertResult);
      insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);
      insertStmt.execute();
      insertStmt2 = new SQLStatement();
      insertStmt2.sqlConnection = conn;
      var sql2:String = "";
      sql2 += "INSERT INTO employees (firstName, lastName, salary) ";
      sql2 += "VALUES ('John', 'Jones', 8200)";
      insertStmt2.text = sql2;
      insertStmt2.addEventListener(SQLEvent.RESULT, insertResult);
      insertStmt2.addEventListener(SQLErrorEvent.ERROR, insertError);
      insertStmt2.execute();
    function insertResult(event:SQLEvent):void
      var stmt:SQLStatement = event.target as SQLStatement;
      stmt.removeEventListener(SQLEvent.RESULT, insertResult);
      stmt.removeEventListener(SQLErrorEvent.ERROR, insertError);
      if (stmt == insertStmt)
      insert1Complete = true;
      else
      insert2Complete = true;
      if (insert1Complete && insert2Complete)
      status.text = "Ready to load data";
    function insertError(event:SQLErrorEvent):void
      status.text = "Error inserting data";
      insertStmt.removeEventListener(SQLEvent.RESULT, insertResult);
      insertStmt.removeEventListener(SQLErrorEvent.ERROR, insertError);
      trace("INSERT error:", event.error);
      trace("event.error.message:", event.error.message);
      trace("event.error.details:", event.error.details);
    function getData(event:MouseEvent):void
      status.text = "Loading data";
      selectStmt = new SQLStatement();
      selectStmt.sqlConnection = conn;
      var sql:String = "SELECT empId, firstName, lastName, salary FROM employees";
      selectStmt.text = sql;
      selectStmt.addEventListener(SQLEvent.RESULT, selectResult);
      selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);
      selectStmt.execute();
    function saveData(event:MouseEvent):void
      status.text = "Saving data";
      insertStmt = new SQLStatement();
      insertStmt.sqlConnection = conn;
      var sql:String = "INSERT INTO employees (firstName, lastName, salary) VALUES (:param, :param1, :param2)";
      insertStmt.text = sql;
      insertStmt.parameters[":param"] = firstName.text;
      insertStmt.parameters[":param1"] = lastName.text;
      insertStmt.parameters[":param2"] = salary.text;
      insertStmt.addEventListener(SQLEvent.RESULT, insertResult);
      insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);
      insertStmt.execute();
    function selectResult(event:SQLEvent):void
      status.text = "Data loaded";
      selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);
      selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
      var result:SQLResult = selectStmt.getResult();
      resultsGrid.dataProvider = new DataProvider(result.data);
    // var numRows:int = result.data.length;
    // for (var i:int = 0; i < numRows; i++)
    // var output:String = "";
    // for (var prop:String in result.data[i])
    // output += prop + ": " + result.data[i][prop] + "; ";
    // trace("row[" + i.toString() + "]\t", output);
    function selectError(event:SQLErrorEvent):void
      status.text = "Error loading data";
      selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);
      selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
      trace("SELECT error:", event.error);
      trace("event.error.message:", event.error.message);
      trace("event.error.details:", event.error.details);

    Your database system may well have a setting for character encoding when creating new databases. If you set that to unicode JDBC should store and retrieve UNICODE strings automatically.
    As to the HTML side, you should generally use UTF-8 encoding. You need an editor which understands UTF-8. JSPs and servlets have ways of specifying the encoding which goes into the http headers. For static HTML pages you may have to add a header like:
    <META http-equiv="Content-type" value="text/HTML; charset=UTF-8">
    When receiving form data you need to do
    request.setCharacterEncoding("UTF-8");

  • Data type for Saving Image in SQL database

    Hi,
        Which is the best way for saving images in the database? Filestream or Varbinary(max)?. Will the Varbinary max comsume much space or it will only take the actual size of the data?

    I've used FILETABLE for storing images in SQL 2012
    You can configure it to have transact and non transact access if you want
    see
    http://visakhm.blogspot.in/2012/07/working-with-filetables-in-sql-2012.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Insert a value of type Date/Time into a database

    I am trying to insert a value of type date time into an access database. What is the format needed to insert the date/time.
    Thanks,
    -Amos

    I had all kinds of problems getting a datetime inserted into a SQl Server DB. Probably similar so this is what I do:
    String date = new String("01/01/97 12:00:00");
    stmt.setObject(1, date);
    I tried using TimeStamp's but found I got an occasional Fractional Truncation exception back from the driver. Never had a problem inserting a String using the setObject() method though.
    Hope this helps

  • My time machine does not want to save any more the data from my powerbook 13" Snow Leopard; i get the message "Time Machine could not suppress the disk image of saving "Volumes/Time Capsule Disk/PowerBook _2011_03_21_123627 sparsebundle" What should I do?

    My time machine does not want to save any more the data from my powerbook 13" Snow Leopard; i get the message "Time Machine could not suppress the disk image of saving "Volumes/Time Capsule Disk/PowerBook _2011_03_21_123627 sparsebundle" What is the problem? What should I do?
    Thanks !!
    Alain

    Could that read " . . . could not access . . ."?  If so, try repairing your backups, per #A5 in Time Machine - Troubleshooting.
    If not, or if that doesn't help, see #A1 there. Use the TM Buddy widget it details to copy and post the messages here.

  • Date Time in Coldfusion at Daylight Saving

    Hi
    In coldfusion, I have problem creating Date Time using CreateDateTime when the daylight saving switch. For example
    CreateDateTime(2011,3,13,2,0,0) gives error.
    Also if you do like this
    DateAdd('h',1,CreateDateTime(2011,3,13,1,0,0)) gives "2011,3,13,3,0,0" ie instead of 2AM it returns 3AM. This is happening every daylight saving switch time.
    This is a bug in coldfusion?
    It should be fixed by Coldfusion.
    Thanks

    On 3/17/2011 12:39 AM, Paresh_Patel said:
    >
    When we loop through the 24 hours on daylight saving day e.g
    >
    <cfset startDate = CreateDateTime(2011,3,13,0,0,0)>
    >
    <cfoutput>
    <cfloop from="1" to="22" index="dayNo">
          <cfset startDate = dateAdd('h', 1, startDate)>
          #hour(startDate)#<br>
    </cfloop>
    </cfoutput>
    >
    This will show wrong hours (2 is missing)
    and that means you've fallen into timezone hell.

  • Add current Date/Time to a database note?

    If we set the database note when we are loading the cube, what would be the syntax to set the current date/time?<BR><BR>For example...<BR><BR>ALTER DATABASE <NAME> SET NOTE <COMMENT><BR><BR>What would go in <COMMENT> in order to set current date/time?<BR><BR>Cheers!

    Hi Philip,
    There is an SAP formula variable to supply the current date in a formula. I think it is 0F_ADAY...install it from business content if you cannot see it in the query designer (formula box, under formula variables) and try using it.
    Hope this helps...

  • Type of object from a database date/time column

    Hello everyone,
    I've got a concern regarding the way in which coldfusion is
    treating date/time columns in a database.
    In my opinion when I select a column that is let's say
    timestamp type - the object in a query is CF's date/time object.
    I've checked the query by getMetaData() and it looks like each
    column has its own database type (eq. varchar2, date, etc).
    My concern comes from a fact that I've heard that Coldfusion
    is treating the date-time columns in a database as strings and in
    each case it parses them. So the difference in a locale between a
    database server and a Coldfusion server may result in a wrong
    date/time object.
    Example:
    Locale of database EU: yyyy/mm/dd
    Locale of Coldfusion US: yyyy/dd/mm
    The date like 1st of February 2007 stored in a database would
    look then in Coldfusion like: 2nd of January 2007
    Could someone please confirm which version is valid?

    Johnny852 wrote:
    > In my opinion when I select a column that is let's say
    timestamp type - the
    > object in a query is CF's date/time object. I've checked
    the query by
    > getMetaData() and it looks like each column has its own
    database type (eq.
    > varchar2, date, etc).
    if you already know cf is returning a datetime from a
    datetime in the db, what's
    the question?
    > My concern comes from a fact that I've heard that
    Coldfusion is treating the
    "fact"? unless the datetime is stored as a string, that's not
    a "fact".
    > Example:
    > Locale of database EU: yyyy/mm/dd
    > Locale of Coldfusion US: yyyy/dd/mm
    btw neither of your example "locales" are in fact locales.
    > The date like 1st of February 2007 stored in a database
    would look then in
    > Coldfusion like: 2nd of January 2007
    if you pass a numeric string representation (2/1/2007 for
    instance) of a date to
    cf, it will be interpreted via the cf server's "default"
    local (ie en_US,
    month/day/year) unless you use one of the LS functions like
    LSParseDateTime() &
    specifically set the the locale (like setLocale("th_TH")) or
    make the date
    non-ambiguous (2-feb-2007) or build the date yourself from
    user input using
    createDate() or createDateTime(). you just need to convert
    the user's string
    representation to a valid cf datetime object (or i guess
    force to database to
    follow the user's locale date mask).

  • Saving to and collecting data from a database

    I am working on  a small project where 3 forms need to interact with each other. Form 1 should be completed then the information saved to a database then form 2 called and because of common fields between the 2 forms...data should be populated from the database to form 2 (data that was entered from form1).
    How is this done? Whats the javascript solution for this issue? the code used to save information from a text field, combobox and to retrieve it to populate another?
    Thanks in advance

    This is typically implemented as a LiveCycle orchestration:
    Form 1 is completed and submitted to a LiveCycle orchestration on the server
    The orchestration saves the submitted data to the database and then uses it to pre-populate Form 2
    Form 2 is sent to the user
    Common options for these steps include:
    Submission by email using a LiveCycle email end-point or secure, seamless submission by HTTPS to a web component (e.g. servlet or ASP.NET page) that calls the orchestration as a web service using the LiveCycle SOAP end-point
    Form Pre-population is performed using Forms Data Integration (FDI) or LiveCycle Forms
    Form is sent to user either by email or streamed back in same session if using HTTPS
    Avoka Technologies provides a pre-built web component Process Invoker that makes it easy to implement the HTTPS submission option.
    Of course, if the forms are filled out by the same user, you could merge them into one form and collect all the data on the client side before submitting to the server. You can even use show/hide to give the user the experience of filling out multiple forms if that is desired.
    Ben Walsh
    www.avoka.com

  • IPhone upgrade to 3.1.2. resets date time - no daylight saving

    I upgraded my iPhone 3GS to the new OS: 3.1.2 recently. I noticed the date & time were reset to some time way in the past so I reset them to the current date & time. I notice now there's no way in the Settings | General |Date & Time to automatically have the date & time synced with your PC and the iPhone doesn't take allowance of daylight saving time - I added London as a city for keeping track of my time and the Clock shows it as 10 hours behind Sydney time rather than 11, which would be the case if Sydney was set at daylight saving time.
    Does anyone have any suggestions as to how I can get my iPhone to recognise daylight saving time again? I can't see anywhere on the iPhone or iTunes to do it, I've tried resetting my iPhone. Nothing is working.

    I don't see a DST option either. I assume that Set Date & Time automatically did set from the phone network and that would include DST corrections. Mine is correct now and we are on DST here. Manual says:
    "Set whether iPhone updates the date and time automatically: Choose General > Date & Time and turn Set Automatically on or off.
    If iPhone is set to update the time automatically, it gets the correct time over the cellular network, and updates it for the time zone you’re in.
    Some carriers don’t support network time in all locations. If you’re traveling, iPhone may not be able to automatically set the local time."
    Phil

Maybe you are looking for