How to use system date and time

Hi i am using mysql database.
my code is import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpSession.*;
import java.io.*;
import java.sql.*;
public class TaskA extends HttpServlet
  public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        java.sql.Date Taskdate = new java.sql.Date(System.currentTimeMillis());
        //long Time1 = System.currentTimeMillis();
        String UserName = request.getParameter("UserName");
        String Task = request.getParameter("Task");
        String Assignedby = request.getParameter("Assignedby");
        String Assignedto = request.getParameter("Assignedto");
        String status = request.getParameter("status");
        String Taskdesc = request.getParameter("Taskdesc");
        try
             Class.forName("com.mysql.jdbc.Driver");
             Connection con = DriverManager.getConnection("Jdbc:mysql://localhost:3306/sandeep?UserName=;Password=","root","digi");
             Statement stmt;
             stmt = con.createStatement();
               ResultSet rs = stmt.executeQuery("select UserName from Empinfo where UserName ='" +UserName +"'");
                if(!rs.next())
                     out.println("UserName may not valid ! u r Task was not Allocate successfully");
               else
                    //rs.getString(1);
               PreparedStatement st  = con.prepareStatement("insert into Taskinfo values(?,?,?,?,?,?,?)");
             st.setDate(1,Taskdate);
             st.setString(2,UserName);
             st.setString(3,Task);
             st.setString(4,Assignedby);
             st.setString(5,Assignedto);
             st.setString(6,status);
             st.setString(7,Taskdesc);
             st.executeUpdate();
             out.println("<html>");
             out.println("<body bgcolor =#cdcdb4 >");
             out.println("your task sent successfully");
             out.println("</body>");
             out.println("</html>");
               rs.close();
          catch(Exception e)
               out.println("Driver is not found:    "  +e);
}and afrer it get execute only date is store in database but not system time.but i want to store both date and time together.
i am using DATETIME datatype in mysql.
whats a problem in my code.

You might want to use TimeStamp and not java.sql.Date which by definition does not include time.
You might also want to close PreparedStatement and Connection in your code.

Similar Messages

  • How to get system date and time?

    Can someone show me a code on how to get system date and time.
    Thanks!

    there is one really easy way to get system time, the api gives a great example of code on this. use gregorian calendar, which you'll find in the api under GregorianCalendar. You only need to create one instance of GC, ie Calendar time = new GregorianCalendar();
    you save seconds, minute and hours into int values, so you don't have to access the system time every second, you can create a thread which adds one to the int second value, if oyu see what i mean, for example, i have saved the hours, minutes and seconds as int values;
    int hour, minute, second;
    i can then create a thread (Thread thread = new Thread(this) and run it like:
    Calendar time;
    int hour, minute, second;
    Thread thread = null;
    public MyTime() {
    hour= time.get(Calendar.HOUR_OF_DAY);
    minute = time.get(Calendar.MINUTE);
    second = time.get(Calendar.SECOND);
    if(thread == null) {
    thread = new Thread(this);
    thread.start();
    public void run() {
    Thread t = Thread.currentThread();
    while(thread == t) {
    thread.sleep(1000);
    second++;
    if(second > 59)
    minute++;
    if(minute>59)
    hour++;
    formatTime();
    public void formatTime() {
    second = (second > 59? 0 : second);
    minute = (minute > 59? 0 : minute);
    hour = (hour > 23? 0 : hour);
    System.out.println(hour+":"+minute+":"+second);
    public static void main(String[] args) {
    new MyTime();
    I know this looks like gibberish but it should work. If not, try to fix the problem, i have written from memory really but i guarantee you, this gets the time then every second, simply adds one to the second and then formats time. You can also access the day, month and year then format them using the above code. I don't like giving code since you should really do these things yourself but it is 2:04am, i have nothing better to do and i am not tired so i did you a favour - i have become what i always did not want to, someone ho stays upall night writing code.

  • Automatic file generation using system date and time

    Hi guys,
    Iam trying to generate a path for file creation automatically using System date and time. I am running into errors with respect to special characters in filename. I am trying to parse the string to get date and time without the '/' and ':' but have not been successful. is there a better way to do it? Please help! I am trying to avoid a dialog box for user to enter a filename.
    Thanks!
    V
    I may not be perfect, but I'm all I got!
    Solved!
    Go to Solution.

    here is a little experiment .... building the path out of %m (month) %d (day) %(year) type stuff might help.
    Attachments:
    putting time in path.vi ‏7 KB

  • How to pass system date and time with tabular from in Update only Mode.

    Dear Friends,
    i have created tabular form with UPDATE Only .here i am assigning work to another multiple users.i want to insert system date and time when i assign work to multiple users.
    How can i insert system date and time into table using tabular form in Update Only Mode.
    beacuse i have pass in default system date it's working only with add row button.
    How can i pass system date and time in update mode in tabular form.
    Thanks

    Hi,
    You just create a trigger on the table on which you build your tabular form:
    e.g:
    CREATE OR REPLACE TRIGGER  "AUDITING"
    before insert or update on "MYTABLE"
    for each row
    begin
        if inserting then
            :new.created_on := localtimestamp;
            :new.created_by := nvl(v('APP_USER'),user);
        elsif updating then
            :new.updated_on := localtimestamp;
            :new.updated_by := nvl(v('APP_USER'),user);
        end if;
    end;Regards,
    Fateh

  • Extracting Time without using the System Date and Time

    Hi, can I know how to process a task at this particular time eg. 6PM everyday without using the System Date and Time..
    Do I need to use a Timer to get this done or is there any other solution to do this? Can give me a few hints? Thanks in advance =D

    You could use a timer...assuming you had some good reference point when you started so you would know that from your starting point it's now 6pm.
    I thought I saw you asked this question once already...and you were given a similar answer....I think by Sylviae?

  • How to get the date and Time?

    Hi,
    I am using Jdev 11.1.2.0.
    I had one database table. In that table one variable as bgnDtm and the datatype as oracle.jbo.domain.Timestamp. In my Impl class I declare one variable as beginDate(DateType as oracle.jbo.domain.Date).
    Now I am using the conversion as beginDate=(Date) SampleVO.getAttribute("bgnDtm ");.If I using this scenario I got the Type cast error. so how can I separate Date and Time value.
    So how to do. Please provide some suggestions.
    Regards,
    Ragu.

    you can get the time value either from oracle.jbo.domain.Timestamp or from oracle.jbo.domain.Date
    oracle.jbo.domain.Timestamp timeStampDate = (oracle.jbo.domain.Timestamp) SampleVO.getAttribute("bgnDtm");
    Time time;
            try {
                time = timeStampDate.timeValue();
                System.out.println(time);
            } catch (SQLException e) {
                e.printStackTrace();
            java.sql.Date sqlDate=timeStampDate.dateValue();
                oracle.jbo.domain.Date jboDate=new oracle.jbo.domain.Date(sqlDate);
            Time timeValue = jboDate.timeValue();
            System.out.println(timeValue);Edited by: M.Jabr on Dec 23, 2011 1:55 PM

  • Time Stamp Error: Cannot display system date and time. My VI display "YYYY-MM-DD" instead of "2014-08-02".

    Hi All,
    I am using Labview8.5 and Windows XP OS.
    My Problem is my Labview TimeStamp cannot display current system date and time.
    Please see my attachment for the screentshot.
    The TimeStamp or ever Format Date/Time String display "YYYY-MM-DD" instead of  "2014-08-02".
    I tried other computer machine and it works. There are some computer machine has this problem.
    How can I resolve this issue? Please advice. Thanks.
    Best Thanks,
    Jessie
    Attachments:
    Time Stamp error.JPG ‏68 KB

    Bill,
    reviewing the thread Dennis linked (thanks for that) reveals that it is the same account which opened this thread here three month later.
    What bothers me is the fact, that the past thread is marked "solved" even though it obviously isn't. Or the OP is trolling us.....
    Nevertheless, it seems like systematic error. Connected to specific machines.
    What makes the machines where the time stamp issue occurs "unique"? If there are several, is that source really "unique"?
    Most obvious reasons would be:
    - Language settings (possibly the infamous "dot-comma-issue")
    - Time zone settings (e.g. what happens if you switch Ulaanbaatar to Perth or maybe even some US time zone?)
    - Missing hotfixes for Win and LV
    - Is the system running as virtual machine vs. "native"?
    Not so obvious differences:
    - Specific CPU type
    - Motherboard/BIOS
    - LV ini settings
    There are tons of other possible reasons (e.g. corrupt LV installation), but these are the ones i came up with within a couple of minutes....
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • How to use system date in filter?

    Hi experts,
    I'd like to use the system date on a filter using the query designer but I don't know how I should do it. I have two characteristics that represent the date and the time that I want to filter. I want to use the system date and time to filter those characteristics. Is it possible?
    Thanks.

    Create one Customer Exit Variable, and assign sy-datum as value to it in Exit Code.
    Current System date in report

  • I need to get the Current System Date and time in the format

    I need to get the Current System Date and time in the format
    *6/24/2009 11:30:29 AM*
    How do i do it ?

    I seem to be saying this a lot lately.
    Google is your friend.
    I googled "java current date format" and SimpleDateFormat featured prominently in the results.

  • How to find the Date and Time of Modification of Column in aTable?

    Hi all,
    Do  you know how to find the Date and Time of Addition of Column to a Particular Table?.
    I know however, How to find the modification time of the Table. Using the below Query :
    Select Object_Name, to_Char(Last_DDL_TIME, 'DD-Mon-YYYY HH24:MI:SS') Last_DDL from User_Objects where Object_Type = 'TABLE';
    Object_Name
    Last_DDL
    Employee
    20-Aug-2013 09:23:03
    I wanted to know the Creation or Modification Date and Timestamp of all columns of Employee Table?. Is it possible at all. If possible, How to get it?.
    Regards,
    Bhaskar M

    I agree with you on that. Since its a development enviornment I can remove the column but that not my point here.
    My whole purpose it to know whether we get the Column's Creation or Modification DateTime.

  • How Production Order finish date and time is being comptued by SAP?

    Hello Expert,
    How Production Order finish date and time is being comptued by SAP? for example, we create a Production Order via CO01, the basic start date is 29.09.2008 and time is 04:00 it gives us basic finish date is 29.09.2008 and time is 13:28.
    how does SAP compute the time 13:28 as it finished time
    Please explain me briefly.
    Thanks
    Ryan

    Hello Guys,
    When we create Production Order in R/3 the time is calculated by routing but it is extended at SetUp machine time. It is not correct?. SetUp imachines time used only for first Production Order for the same product and it is plan manually, for others Production Order we need calculate time for production without SetUp machine time being pick up to compute finish time. how could we achieve this? only those Machine time will be check.
    thanks

  • How do i show date and time info of videos in Iphone as they appeare before import in iPhoto?

    How do i show date and time info of videos in Iphone as they appeare before import in iPhoto? or even as they appear on the iPhone itself? The selection on tool bar for show info is greyed out.

    Welcome T G Brown to the  iMovie boards..
    the socalled timestamp is within the imports.. if you select a clip in iM and hit the key combo Apple-I, you can see recording time and date.
    unfortunately, this info isn't delivered to any software. Bruce Gee (geethree.com, excellent plug-in maker) told us, there's no 'API' he could use for such a feature...
    same on the pro side, read this discussion at the FinalCutExpress boards:
    http://discussions.apple.com/message.jspa?messageID=7982935
    Forum member Ian offers a solution with a 3rd party app ....
    so: pen&pencil and typing timestamp manually into any 'Title' seems to be your only option...

  • Samsung Galaxy S 5 - using automatic date and time

    Using automatic date and time sets the date to November 27, 2014 instead of the correct date of September 25, 2014. What's going on? I haven't ever had a problem with this setting before.

    Clear phone system cache & place phone in Airplane mode then do a power down (not a restart) of the phone. Next remove both SIM card and battery & wait for 1 minute or so. Then reinstall the SIM & battery and power phone on. If your signal is strong this should reset your data channel to the correct time. 

  • How do I set date and time on apple tv?

    How do I set date and time on apple tv?

    Fixed the same problem, STEPS
    1. Reset your apple TV
    2.It will again stuck on that setting, ignore it by press menu
    3. Unplug ethernet wire
    4. Try to connect with wifi, it should be work with wifi connection as mine.
    5. Then you can switch back Ethernet wire after get fixed.
    Thanks. Lemme know dude if it's work.

  • Camileo S20 - How to display the date and time

    Hi, to all. I have got as Christmas present the Camileo S20 and I am not able to display the date and time at video. In manual is no mention about this, just how to set the correct date and time. But what is intention of setting the date and time into camera, if it is not possible to display them on video ?

    Hi,
    of course, I did it repeatly, it is written in my question above. I am not stupid.
    This question is aimed to owners of camera Camileo S20 and also Camileo S10 - Camileo S20 is derived of Camileo S10, may be any of them discovered the way how to get the date and time into video.

Maybe you are looking for

  • Final Cut Pro working very sluggish, any suggestions ?

    Hello everybody, I've been using Final Cut Pro for a very long time now. Although I've had this problem lately, when the smooth cam analyzation finishes. Final Cut pro ( the Video which was analyzed successfully ), starts working very slow. Something

  • Program error

    I'm trying to open a photo to edit and I get the response, "can't open file due to a program error"  I get this response with any photo I try and open.  I am running Mac Os Lion.  I purchased elements 10,  3 weeks ago and it worked fine when I used i

  • WebView weird rendering issue (Color rectangles) - Debug Mode

    Hi, i got a problem with a JavaFX Webview. Everything loads fine, but every single Element in the DOM of the page (including the body) is overlayed with a random colored rectangle when hovered. After a few seconds the entire page is renders unreadabl

  • Features in Photoshop Elements

    Hello: I have a VERY old version of Photoshop. I rely heavily on drawing paths and recording and playing actions. I would like to upgrade to a newer version, but since mine is so old, I would have to pay full price for CS4. Does anyone know if Elemen

  • Partition Query

    On a Lenovo T61 running Vista there is a "hidden" 7 GB partition that is for a recovery operation. The balance of the Hard Disk is C. There is no D. The CD/DVD Reader/Burner is E. Am I able to use the Vista builtin facilities to shrink C to 20GB, and