Convert a string to date, so that i can insert it on SQL database

Hi, me again..
i have this variable
date.getText()
i want to convert it to date, so i did this:
d = (Date) DateFormat.parse(date.getText());
but it says "Cannot make a static reference to the non-static method parse(String) from the type DateFormat"
what the hell is that?
can someone help? i want the date to correspond to the variable format on my database (DATETIME (yyyy-mm-dd))

GMX750 wrote:
OK, like this?:
DateFormat df;
df = DateFormat.parse(data.getText());
i did this, but the IDE says the same thing
: \If you don't know the difference between static and non-static methods, or how to instantiate an object, you're not ready to be messing with JDBC yet. Sorry if that sounds harsh, but it's the truth. If you keep trying to go down this path without getting a handle on the fundamentals, you're just setting yourself up for more frustration and a poor excuse for an education.
Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806].

Similar Messages

  • How to convert a String to Date?

    i have a String "1998-12-31" i would like to convert it to Date so that i can compare the Date in Mysql.
    i am appreciate for your help.
    Thanks
    yuetni Swee

    hi,
    i try to change the code by using the code below do you think it is ok
    i just use the Date.valueOf(String s) method. is it still working in sql?
              java.sql.Date PickDat = java.sql.Date.valueOf(PDate);
              java.sql.Date DropDat = java.sql.Date.valueOf(DDate);
              System.out.println("IN CARINFO FUNC." + pickdropPnt + PDate + DDate + carclass);
                   sql.append("SELECT * FROM CARS");
                   sql.append("WHERE TO_DAYS('" PickDat "') BETWEEN TO_DAYS('FROM_D') AND TO_DAYS('UNTIL_D') ");
                   sql.append("AND TO_DAYS('" DropDat "') BETWEEN TO_DAYS('"+PickDat+"') AND TO_DAYS('UNTIL_D') ");
                   sql.append("AND PICK_UP_DROP ='" + pickdropPnt +"' ");
                   sql.append("AND CAR_TYPE ='"+carclass + "'");

  • How to convert a string to date and then compare it with todays date???

    Hello.
    I want to set a format first for my dates
    DateFormate df = new SimpleDateFormate("yyyy-mm-dd");
    once this is done then I want to convert any string to date object in the above formate
    String str="2001-07-19";
    Date d = null;
    try{
    d = df.parse(s);
    }catch(ParseException pe) {
    pe.printStackTrace();
    First of all there is something wrong above,cus what I get for this is
    Fri Jan 19 00:07:00 MST 2001
    where as it should have been
    2001-07-19... to my understanding.
    once this part is done I need to get current date in the above set format and compare the
    current date and the date I set.
    I will appreciate the help.
    Thanks

    for the output part:
    a date is a point in time
    the output depends on the format you specify for output
    using for example a SimpleDateFormat.
    You only specified the format for parsing (which is independent for that of output) so java uses some default format ... see the DateFormat.format() method for details.
    for the comparison stuff, I just posted a little code snippet in this forum a few minutes ago.
    the hint is: Date.getTime() returns milliseconds after a fixed date
    hth Spieler

  • Converting iMovie format to a format that I can edit with Adobe Premier Pro

    How can I convert iMovie format to a format that I can edit with Adobe Premier pro 7 program?

    Install the free flip4mac player and you'll be able to view it.

  • Hi, Im trying to convert a PDF into a weblink that I can post onto social media  but dont know how, can you help please?

    Hi, Im trying to convert a PDF into a weblink that I can post onto social media  but dont know how, can you help please?

    You need to upload it to some kind of public server, or file-sharing site (like Google Drive, Dropbox, etc.), and then post the link to it.

  • How do I convert a .ced format into something that imovie can recognize?

    Anyone now how to convert a .ced file into something that imovie can recognize?

    Just google.
    http://www.google.com/search?client=safari&rls=en&q=.ced+file+converter&ie=UTF-8 &oe=UTF-8

  • When jpeg's are sent as email attachments from other computers, they arrive on my imac as winmail.dat files that I can't open.  What do i need to do to receive such attachments as jpegs that I can open?

    When jpeg's are sent as email attachments from other computers, they arrive on my imac as winmail.dat files that I can't open.  What do i need to do to receive such attachments as jpegs that I can open?

    tommybwin wrote:
    Perhaps go edit>attachments>always send windows-friendly attachments.
    That has no effect on emails that you receive.

  • Can I purchase an IPhone 5 that is factory unlocked, so that I can insert my t-mobile sim card and use it on my service from the apple store?

    Can I purchase an IPhone 5 that is factory unlocked, so that I can insert my t-mobile sim card and use it on my service from the apple store?

    Not in the US, at the present time. Apple has not started selling officially unlocked iPhone 5's in the US, & has not announced when they will.

  • HT4993 I was advised by sprint to request that you unlock my iPhone so that I can insert international sim card when I travel to Africa. My travel is due soon.

    I like to have my iPhone of sprint network unlocked so that I can insert international sim card when I get to nigeria to use it for calls there please help and reply asap
    <Edited By Host>

    Only Sprint can unlock your phone. Call them back.
    This is a user-to-user technical support forum. You're not addressing Apple here. I've also requested that the Hosts remove your mobile number from the post. 

  • Convert from String to Date for storing in SQL Server 2000

    Hi,
    I've accepted some values from a user using a form in HTML.Now using Servlets I transfer the value to my java code .
    I want to know how can I convert a DATE accepted from the user thats presently in "String" format to the "datetime" format for SQL Server2000.
    Please guide me with some steps and I shall be grateful.
    Thanks

    The java.text.SImpleDateFormat class is most probably of use.
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    String enteredDate = "25/12/2006";
    java.util.Date utilDate = sdf.parse(enteredDate);
    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());You can then use the java.sql.Date with the "setDate()" method of a prepared statement. This method would be database independant, as you are setting an actual date, not depending on a specific format on the database end.

  • Converting a string into Date format

    I am currently using a JSP.
    I currently need to convert a string that holds a date in "dd/mm/yyyy" format to the jva.sql.Date format.
    Any ideas as to what the proper way of doing this is?
    Many thanks ppl

    public java.sql.Date parseDate(String s) {
         java.text.DateFormat dateFormatter= new java.text.SimpleDateFormat("dd/MM/yyyy");
         return new java.sql.Date(dateFormatter.parse(s).getTime());

  • Problem in converting the String to Date with time zone GMT

    Hi,
    When I tried to convert the string 12/05/2009 to Date, the time zone is set to BST.On the other hand, for the date 12/12/2009, the time zone is set to GMT. What should I do to get the time zone as GMT all the time.?
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    String dateString = "12/05/2009";
    System.out.println(myDate.toString());

    I think you are all missing the point. java.util.Date objects always alway always store the date as the number of milliseconds since 1/1/1970 UTC so the only TimeZone they have its the implicit UTC. When you use the Date.toString() method the toString() method gets the default time zone from your environment and formats the data accordingly. This means that the same Date object will, by default, produce a different result for France and Australia and the US.
    So, if you have the date "12/5/2009" as a String then to convert it to a java.util.Date you must specify what TimeZone is implied. If it is your system time zone then you can just create a SimpleDateFormat object with the correct format and then use the parse() method to create the java.util.Date object and this will automatically be converted to UTC. If the date String represents some other time zone then you must explicitly set the time zone of the SimpleDateFormat object before parsing the string.
    The same approach applies when converting a java.util.Date object to a String. If you want anything other than your system time zone then you must explicitly tell the SimpleDateFormat what time zone you want the result formatted for.

  • Converting a String to Date

    I have a String in which i am storing the date which I have retrieved from database. How can I convert this String to a Date object and use Comparator for sorting.
    String strCreatedDate1 = ((CVendorEmployees) vendoremployee1).getCreatedDate().toUpperCase();The date format which I will retrieve from String is mm/dd/yyyy.
    I want to convert this into date and use it for sorting.
    Thanx.

    Date dtTmp = new
    SimpleDateFormat("dd-MM-yyyy").parse(((CVendorEmployee
    s) vendoremployee1).getCreatedDate());
                                  Calendar calendar = Calendar.getInstance();      
                                  calendar.setTime(dtTmp);
    Now you have the date object do what ever you wish toBetter make thatnew SimpleDateFormat("MM/dd/yyyy")And no need for the Calendar stuff if all you want is a Date object.

  • How to convert a String to Date format?

    the user enter a date in string format and the date is save in the database.
    The problem i am facing is i want to change from String to Date format.
    Here is my codes:
            public boolean insertData() throws Exception {
            boolean validFlag = false;
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date d = df.parse("05/18/05");
            String MY_DATE_FORMAT = "yyyy-MM-dd";
            String jobAdvertisementDate = new SimpleDateFormat(MY_DATE_FORMAT).format(d);
            String sql = "INSERT INTO companyjob (CompanyID,JobID, JobAdvertisementDate ) " +
                    " VALUES ('" + companyID + "','" + jobID + "', '" + jobAdvertisementDate + "')";
            System.out.println(sql);
            validFlag = executeSQL(sql);
            return validFlag;
        }The date is save under jobAdvertisementDate.
    My netbeans shows an error. There's a red line under DateFormat and parse inside my codes.
    PLease help me. Reply asap!!

    BebeGirl wrote:
    My netbeans shows an error. There's a red line under DateFormat and parse inside my codes.
    Red Line? Sounds ominous. I wonder what it means.
    So...what does the error say?

  • How to convert a string to date using OLEDB function?

    Is there any function similar to OCIDateFromText()?
    I have to read the date from a text file and store it in the sql database in a date column.
    Please suggest how to do it?
    Thanks in Advance.

    In addition, SQL Server 'likes' YYYYMMDD format to operate with dates.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for

  • Comparar colunas de duas listas do Sharepoint 2013

    Pessoal, minha dúvida é a seguinte: Tenho duas listas no Sharepoint, a Lista A que é uma lista com um termo de aceite, onde você deve preencher com seu CPF e clicar no botão de aceite do termo. A Lista B possui uma base de dados com todos os usuários

  • Forte For Java GUI Editor

    Hi everyone, I've been trying to switch usage between Forte for Java running on 2 platforms (Win NT and Solaris 8). For this reason, I want to try to use the GUI Editor in each. But when I tried copying the same .class file from one platform to anoth

  • How to avoid the truncation of  field values in select-options

    Hi all, I have a requirement where i have used select-options to select multiple filenames.  I have taken the filename of type rlgrap-filename(128 char) But the problem is in select-options if the values of the filename which is selected has length (

  • The different types of User accounts

    Hello, This mainly stems from the fact I would like to add a Router to my CNA (Cisco Network Assistant) community.  And am not sure which user credentials I need to apply on CLI. To note I have enabled IP http server. So from the list below what are

  • Mapviewer multi basemap problem with Bing Layer

    We would like to open Bing Layer tile layer over our oracle mapviewer basemap. We are getting following error. [MVMapView.addMapTileLayer] MAPVIEWER-05528: Map tile layers have different zoom level definitions. Only the map tile layer added later wil