How to use  JtextFild with java.util.Date;

hi
My problem is that i have a date data type field inaccess in table.
Otherside i use JTextField.
First when this window show i initialize this field with current date.
The code for this is
lbdate = new JLabel("User Date",JLabel.RIGHT);
          lbdate.setBorder(new EtchedBorder());     
          txtdate = new JTextField();
          txtdate.setBorder(BorderFactory.createLineBorder(Color.red));
          //month convert into string
          int m = cal.get(Calendar.MONTH);
          m++;
          String mon = Integer.toString(m);
          //day convert into string
          int d = cal.get(Calendar.DATE);
          String date = Integer.toString(d);
          //year convert into string
          int y = cal.get(Calendar.YEAR);
          String year = Integer.toString(y);
          txtdate.setText(mon+" / "+date+" / "+year);
i am not satisfied by this. How can initialize the JtextField by some other method.
The secound part of question is that how to reterive the date data type of field and see in the textfield.I see butt it returns like this year/month/date(this date is coming from database which already input) 00:00:00
How can i discard 00:00:00(this time)
I code for this is
Date date = rs.Date();
txtfld.setText(date); //Here error is occured of TypeCasting
and tell me that how date type object can convert into String for set the text of field
because JTextField only accept the String data.
(if u illestrate with code).
thanks

Use a JFormattedTextField with a SimpleDateFormat in parameter.
Denis

Similar Messages

  • Getting error by ValueBinding with java.util.Date

    Hi.
    1. my english is not so good.
    I develop a JSF-application to learn more about JSF-technologie.
    I use Eclipse 3.2
    Plugins: Web Tools Platform (WTP), Web Standard Tools, Java Server Faces // Version 1.5.0
    JRE: 1.5
    java-impl.jar and java-api.jar (sun)
    Look at this JSP-File Code
    <h:inputText id="dbirth" value="#{dataBean.dbrith}"> </h:inputText>
    this produce an error: EL expression does not evaluate to expected types for this attribute
    dataBean is a ManagedBeain. So if I use any athor variable from this Bean like:
    <h:inputText id="sname" value="#{dataBean.sname}"> </h:inputText>
    is going well. But if I use any java.util.Date variable it produce the error.
    I tried with other Bean and the error is still there.
    I can compile and use this JSP, but this error is there.
    Have any one an idea what is happen there??
    I looked at Eclipse forums, but I didnt found description for an error like this..
    thanks for any help...
    naba
    Message was edited by:
    NamboTango

    The problem is because you have bound the inputText to a java.util.Date object, instead of a String. You must use Strings with inputText. However, JSF has provided a way for you to convert objects into a String. It just needs to know how to do that. Luckily for you, there is a converter already available to convert a Date object into a String. Converters will also take input Strings and convert them into an object.
    So, in your case, use the convertDateTime tag. Like this:
    <h:inputText id="dbirth" value=#{dataBean.dbrith}">
         <f:convertDateTime type="date" pattern="MMM dd, yyyy" />
    </h:outputText>Try it. You may change the pattern to whichever valid one you like.
    CowKing

  • What's wrong with java.util.Date type?

    Hi!
    When I try to persist object having field of type java.util.Date I get the
    following SQL logged by Kodo with subsequent transaction rollback:
    2002-11-14 15:03:35,099 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnecti
    onFactoryImpl.supportcrm/kodo] INSERT INTO BILLY.TT_COMMENTS(COMMENT_TYPE,
    TEXT,
    CREATED_BY, ID, SUBJECT, CREATE_DATE, TT_MAIN_ID) VALUES (1, '1', 10, 279,
    '1',
    {ts '2002-11-14 15:03:35.059'}, 147)
    When I change "{ts '2002-11-14 15:03:35.059'}" with "TO_DATE('2002-11-14
    15:03', 'YYYY-DD-MM HH24:MI')" in SQL editor
    and execute it everything works fine.
    What does "{ts '..'}" mean? Is it a SQL generation error?
    Thank you in advance.
    Best regards,
    Alexey Maslov

    I've created my own dictionary with dateToSQL() method overridden.
    Now it works fine. But it's a kind of strange. Oracle is used often and my
    JDBC drivers
    are the most recent (at least, from the oracle.com).
    Anyway, thank you again.
    "Alexey Maslov" <[email protected]> wrote in message
    news:[email protected]...
    Patric,
    Thank you for response.
    We're using Oracle 8.1.7 via OCI driver from Oracle 9.2.
    I've already tried 2.4.0 and it works fine there but I've found another
    problem there
    preventing me from using it. See my post in solarmetric.kodo.betanewsgroup.
    >
    "Patrick Linskey" <[email protected]> wrote in message
    news:[email protected]...
    That's odd -- what version of Oracle are you using?
    Moving to Kodo JDO 2.4.0
    (http://www.solarmetric.com/Software/beta/2.4.0) will almost certainly
    get rid of this problem, as we use exclusively prepared statements in
    it, and therefore pass dates etc. to JDBC as parameters.
    But, to get things working with your Oracle database and Kodo JDO 2.3,
    you could create your own extension of OracleDictionary and override the
    dateToSQL() method to generate the appropriate TO_DATE() syntax. See our
    documentation for more details on creating custom database dictionaries.
    -Patrick
    Alexey Maslov wrote:
    I've added TRACE level logging for transactions in JBoss and got
    original
    exception:
    NestedThrowables:
    com.solarmetric.kodo.impl.jdbc.sql.SQLExceptionWrapper: [SQL=INSERT
    INTO
    BILLY.T
    T_MAIN(TT_SOLUTION_ID, DELAY_REASON, TT_STATE_ID, ID, CONTACT_PHONE,
    CANCEL_REAS
    ON, OPER_DESCR, TT_TYPE_ID, CREATED_BY, EXP_CLOSE_DATE,SERV_OPEN_DATE,
    OPEN_DAT
    E, FLAGS, TAKEN_BY, TT_CAT_ID, SUBJECT_ID, SUBJECT, SERV_CLOSE_DATE)
    VALUES
    (NUL
    L, NULL, 1, 439, NULL, NULL, '____________ ________________ ________________', 7, 5, {ts
    '2002-11-14 1
    8:38:16.075'}, NULL, {ts '2002-11-14 18:18:16.075'}, 0, NULL, 11,24099,
    '1', NU
    LL)] ORA-00904: invalid column name
    at
    com.solarmetric.kodo.impl.jdbc.runtime.SQLExceptions.throwFatal(SQLEx
    ceptions.java:17)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.insert(JDBCSt
    oreManager.java:421)
    at
    com.solarmetric.kodo.runtime.datacache.DataCacheStoreManager.insert(D
    ataCacheStoreManager.java:265)
    at
    com.solarmetric.kodo.runtime.StateManagerImpl.insert(StateManagerImpl
    ..java:1783)
    atcom.solarmetric.kodo.runtime.PNewState.flush(PNewState.java:31)
    at
    com.solarmetric.kodo.runtime.StateManagerImpl.flush(StateManagerImpl.
    java:372)
    at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.flush(Persistence
    ManagerImpl.java:426)
    at
    com.solarmetric.kodo.ee.EEPersistenceManager.beforeCompletion(EEPersi
    But when I try to execute the statement above against the database
    manually
    everything works fine.
    I'm absolutely desperate!
    P.S. On 2.4.0 RC the operation invoking this database insert completes
    fine.
    "Alexey Maslov" wrote in message
    news:[email protected]...
    Hi!
    When I try to persist object having field of type java.util.Date I
    get
    the
    following SQL logged by Kodo with subsequent transaction rollback:
    2002-11-14 15:03:35,099 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnecti
    onFactoryImpl.supportcrm/kodo] INSERT INTOBILLY.TT_COMMENTS(COMMENT_TYPE,
    TEXT,
    CREATED_BY, ID, SUBJECT, CREATE_DATE, TT_MAIN_ID) VALUES (1, '1',
    10,
    >>>
    279,
    '1',
    {ts '2002-11-14 15:03:35.059'}, 147)
    When I change "{ts '2002-11-14 15:03:35.059'}" with
    "TO_DATE('2002-11-14
    15:03', 'YYYY-DD-MM HH24:MI')" in SQL editor
    and execute it everything works fine.
    What does "{ts '..'}" mean? Is it a SQL generation error?
    Thank you in advance.
    Best regards,
    Alexey Maslov
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com
    Best regards,
    Alexey Maslov

  • What's wrong with java.util.Date??

    Hi all,
    I was just practicing a bit of java.util ,when i was compiling my code-
    import java.util.Date;
    import java.text.SimpleDateFormat;
    class DateStamp{
    public static void Main(String args[]){
    doDate1;
    String D;
    int D1,D2,D3;
    Date dt=new Date();
    SimpleDateFormat sdf=new SimpleDateFormat("dd-mm-yyyy");
    /*When using method .setDate(x) ,is x an integer or String?can x=2/5/2002 or 2-5-2002?*/
    public void doDate1{
    dt.setDay(12);
    dt.setMonth(12);
    dt.setYear(102);
    D=dt.getTime();
    D.parseInt(D1);D=""
    D=sdf.getTime();
    D.parseInt(D2);
    int D3=D2-D1;
    int D3=D3/86400000;/*How do you convert milisec-to-days?*/
    D=D3.toString().
    System.out.println(D+"days have elapsed since then");
    the compiler said this-
    File Compiled...
    --------------------------- Javac Output ---------------------------
    DateStamp.java:7: Invalid expression statement.doDate1;^DateStamp.java:14: Instance variables can't be void: doDate1public void doDate1; ^2 errors
    this problem is persistant, and i'm a java newbie ,Does anyone know what's wrong here?
    Thanks!
    Regards,
    aesh83

    How do you get System date onto a Date variable?Calendar.getInstance().getTime() returns a java.util.Date for the current time. You can also use System.currentTimeMillis() and turn it into a Date.
    Will date.after(Date when) method work when Date
    variables are in milisecs?Date.after(Date when) compares two date objects. As the JavaDoc says "Returns:
    true if and only if the instant represented by this Date object is strictly later than the instant represented by when" To me that says that milliseconds are taken into account, I.E. comparing dates actually compares the date plus the time portion.
    >
    What methods-
    *Convert a date(dd/mm/yy) to milisec?If you look in the javaDoc you'll see "long getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object." Calendar also has the getTimeInMillis() method.
    *Convert a milisec value to a date(dd/mm/yy)?Calendar.setTimeInMillis(long);
    I'm have this little problem.
    When using GregorianCalander-
    *need to initialize?
    *need set today's date?Calendar.getInstance() will return an appropriate Calendar object for the current locale initialized to the current date/time.
    *how do you check if a date exceeds 3 weeks?I'm not sure what you mean. There are a couple of roll(...) methods that will allow you to add a unit of time to a date. I.E. you could add three weeks to a date.
    To ignore the time portion of a date just set the time to "00:00"
    Col

  • How to use connec with java 6.0 ?

    I often use the function below to connect Database:
         public Connection getConnection(){
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn=DriverManager.getConnection("jdbc:odbc:EmployeeManagerDB","sa","sa");
    System.out.println("Get connection successfully!");
    catch(Exception e){
                   System.out.println("Error: " +e);
    return conn;
    but now, with Java 6.0 . don't use "class.forName....for method"
    can you tell me how to use it??
    thanks !

    but now, with Java 6.0 . don't use
    "class.forName....for method" Where did you get this idea?He's perfectly correct. JDBC 4.0 takes advantage of the Java SE Service Provide mechanism in Java 6 to do away with the requirement. So, if you have Java 6 and a JDBC 4 driver (it's a mandatory feature) you simply omit the forName() call.
    The only problem is that there aren't that many complete JDBC 4 drivers out there yet.

  • How to use Entrust with java application on unix platform

    Hi all,
    i have question regarding the use of Entrust with java application on unix
    1)I want to use Entrust for encryption/decryption of the file in my core java application on unix platform.
    What should be requiremnet for the same and how it is implemented?.
    2) I want to Use Entrust for Authentication purpose in my java based web application on unix platform.
    What are requirements for Entrust Authentication and how it is implemented ?

    any one has solution?

  • How to use pda with java application

    hi all,
    i m new to J2ME technology. i have never worked on it. now i want to create java application which communicates with PDA.
    can anyone pls provide me the tutorial link for the same. i m looking in the google but till now i have not got any thing which will give me example of java applicatiion with PDA.
    pls help me out guys.
    thnx in adv.
    regards
    ritu

    hello all,
    i am new to PDA developemt
    i want to create a application in java for PDA using win CE tomcatspring framework
    pls send me some site that have sample code for creating applincation for PDA using java.
    thanks

  • Java.util.Date badly serialized to java.sql.Timestamp Coherence 3.5.2

    Hi all,
    I'm running into this odd behaviour.
    I serialize java.util.Date objects to cache and when I read them back from cache, they appear to be java.sql.Timestamp types.
    I've isolated a junit test for that.
    Do you know why Coherence changes the type in the middle?
    Regards
    Harry.
    import java.util.Date;
    import org.junit.Assert;
    import org.junit.Test;
    import com.tangosol.io.Serializer;
    import com.tangosol.io.pof.ConfigurablePofContext;
    import com.tangosol.util.ExternalizableHelper;
    public class DatePofSerialTest {
         @Test
         public void testCobdate() throws Exception {
              Date date=new Date();
              Serializer serial = new ConfigurablePofContext();//"coherence-pof-config.xml");
              Date date2=(Date)ExternalizableHelper.fromBinary(ExternalizableHelper.toBinary(date, serial), serial);
              System.out.println(serial +" -- Date to serailize ["+ date.getClass() + "]");
              System.out.println(serial +" -- Date from deserialize ["+ date2.getClass() + "]");
              Assert.assertEquals(date, date2);/* Of course this passes, as both refer to the same time (long)*/
    {code}
    This gives as output
    {code:title=output |borderStyle=solid}
    log4j:WARN No appenders could be found for logger (Coherence).
    log4j:WARN Please initialize the log4j system properly.
    com.tangosol.io.pof.ConfigurablePofContext {location=coherence-pof-config.xml} -- Date to serailize [class java.util.Date]
    com.tangosol.io.pof.ConfigurablePofContext {location=coherence-pof-config.xml} -- Date from deserialize [class java.sql.Timestamp]
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi Harry,
    It looks like the same issue as ...
    PofExtractor with java.util.Date results in ClassCastException
    It was fixed in version 3.5.4.
    Thanks

  • Java.util.Date and java.sql.Date

    when i am trying to displaying date in my jsp page errors occurs saying that java.util.date and java.sql.date are matching..
    i have some sql statements which i need to execute in the page.so i cant delete that import sql statement.
    so what is the solution for this.
    i want to display the date as 19th april 2003....in the jsp page.
    thank u

    You should use full names.
    java.util.Date date;
    java.sql.Date sdate;
    ..And it may be a good idea to delete one of the two "import" declaration of packages.

  • How can I use java.util.Date and change display format.

    Hello All,
    I want to use java.util.Date in View Context and in Custom Control Context of Web dynpro java. When i mapped of a Input Field to the java.util.Date then message shows that its not supported. Plz suggest me how to handle Date with different formats ??

    If you always want the user to enter the date in dd/MM/yyyy, you can do the following.
    Goto Local Dictonary -> Simple types in your project and create a type known as "InputDate" (or whatever you feel) of built-in type 'Date'.
    Now specifiy its format in the 'Representation' tab as "dd/MM/yyyy" (case-senstive).
    Now declare a value attribute say "inputdate" in your context with this type and bind the inputfield to this context value attribute.
    This will solve your problem.
    But if you want the user to input date depending on the region he belongs, change the default locale date in Control Panel->Regional and Language Options->Change to English(UK) -> Customize -> Date Tab -> Sort Date Format to dd/MM/yyyy.
    Now clear the cache, delete temporary files and restart the machine. This should solve the problem.

  • How can i compare:  java.util.Date oracle.jbo.domain.Date?

    I have made a ViewObject wich contains a date column.
    I want to check if this date is smaller/greater than sysdate:
    i get following error:
    Error(45,24): method <(java.util.Date, oracle.jbo.domain.Date) not found in class Class4
    code:
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    // set up rules for daylight savings time
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    // create a GregorianCalendar with the Pacific Daylight time zone
    // and the current date and time
    Calendar calendar = new GregorianCalendar(pdt);
    Date trialTime = new Date();
    calendar.setTime(trialTime);
    (VO_ULNRow)singleRow = null;
    while(vo.hasNext()){                                             // ViewObject vo;
    singleRow = (VO_ULNRow)vo.next();
    if(calendar.getTime() < singleRow.getEO_ULN_BORROWFROM()); //singleRow returns oracle.jbo.domain.Date
    etcetera
    how can i compare those 2?

    Hi,
    oracle.jbo.domain.Date has two methods which suit your needs
    longValue() which returns a long (though I'm not sure if returns a long comparable to the long returned by java.util.Date)
    and dateValue() which returns a java.util.Date
    I hope it helps,
    Giovanni

  • Java.util.Date oracle.jbo.domain.Date how can i compare?

    I have made a ViewObject wich contains a date column.
    I want to check if this date is smaller/greater than sysdate:
    i get following error:
    Error(45,24): method <(java.util.Date, oracle.jbo.domain.Date) not found in class Class4
    code:
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    // set up rules for daylight savings time
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    // create a GregorianCalendar with the Pacific Daylight time zone
    // and the current date and time
    Calendar calendar = new GregorianCalendar(pdt);
    Date trialTime = new Date();
    calendar.setTime(trialTime);
    (VO_ULNRow)singleRow = null;
    while(vo.hasNext()){ // ViewObject vo;
    singleRow = (VO_ULNRow)vo.next();
    if(calendar.getTime() < singleRow.getEO_ULN_BORROWFROM()); //singleRow returns oracle.jbo.domain.Date
    etcetera
    how can i compare those 2?

    i get following error:
    Error(45,24): method <(java.util.Date,
    oracle.jbo.domain.Date) not found in class Class4
    if(calendar.getTime() <
    singleRow.getEO_ULN_BORROWFROM()); //singleRow returns
    oracle.jbo.domain.Date
    how can i compare those 2? You cannot compare these two values directly. You must convert the oracle.jbo.domain.Date object to a GregorianCalendar object. Something like:
      oracle.jbo.domain.Date dt = singleRow.getEO_ULN_BORROWFROM();
      GregorianCalendar gc = new GregorianCalendar(dt.getYear(), dt.getMonth(), dt.getDay());
      if (calendar.getTime() < gc.getTime())
      }

  • How to change a date value from "java.util.Date" to "java.sql.Date"?

    Hi all,
    How to change a date value from "java.util.Date" to "java.sql.Date"?
    I m still confusing what's the difference between them.....
    thanks
    Regards,
    Kin

    Thanks
    but my sql statement can only accept the format (yyyy-MM-dd)
    such as "select * from xx where somedate = '2004-12-31'
    but when i show it to screen, i want to show it as dd-MM-yyyy
    I m using the following to change the jave.util.Date to str and vice versa. But it cannot shows the dd-MM-yyyy. I tried to change the format from yyyy-MM-dd to dd-MM-yyyy, it shows the wrong date in my application.
         public String date2str(java.util.Date thisdate)     {
              if (thisdate != null)     {
                   java.sql.Date thissDate = new java.sql.Date(thisdate.getTime());
                   return date2str(thissDate);
              }     else     {
                   return "";
         public String date2str(java.sql.Date thisdate)     {
              if (thisdate != null)     {
                   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                   return sdf.format(thisdate);
              }     else     {
                   return "";
         public java.util.Date str2date(String thisdate)     {
              String dateFormat = "yyyy-MM-dd"; // = 1998-12-31
              java.util.Date returndate = null;
              if (thisdate != null)     {
                   SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
                   try {
                        returndate = dateFormatter.parse(thisdate);
                   } catch (ParseException pe) {
                        System.out.println (pe.getMessage());
              return returndate;
         }

  • Who use sql-mapping with java.util.regex?

    Hi everyone:
    I use the IBatis SQL-Mapping and I think it is very good.Now I want to add the search function to my BBS forum.I also want to display the content high light like jive.I mean that if I want to find the string "ibatis",then the search result "ibatis" will be high light displayed.
    So I must use the java.util.regex in jsdk1.4.But the problem is that what I get is a List if I use sql-mapping.For example:
              String resource="conf/XML/sql/lyo-sql-map.xml";
              Reader reader=Resources.getResourceAsReader(resource);
              sqlmap=XmlSqlMapBuilder.buildSqlMap(reader);
              List articlelist=sqlmap.executeQueryForList("selectSiteArticle","%"+icontent+"%");
    The result I get is a List and I have no time to use regex.
    I don't know whether I could do this:
    Iterate the List,use the regex and later place all the object back to the List.
    It's right?
    How to use regex with sql-mapping?Thks

    Any idea? :(

  • How do I compress a string with  java.util.zip - not a file ?

    How do I compress a string with java.util.zip?
    Is possible to compress something else except a file?

    Of course, compression works on bytes, not some higher level constructs like Strings or files.
    You can use the ZipOutputStream or DeflaterOutputStream for compression.
    And the javadoc for Deflater even has a code example of compressing a String.
    Edited by: Kayaman on May 22, 2011 5:04 PM

Maybe you are looking for

  • To ".mov" or not to ".mov", that is the question

    Hi, Been reading up here on the issue of file extensions. I understand that they are not necessary for OSX/FCP to identify a QT file as a .MOV file. However I am in the process of renaming my clips to clean up a nightmare (long story, but lets just s

  • Shared review requirements - comments disappearing

    Hi, Is there a version requirements for making comments in a shared review .pdf? We have been having problems with some of our co-workers, who work off site and using a VPN connection deleting comments....they were working with version 8, and we were

  • How select a range or portion of a clip when importing?

    Upgraded from FC Studio 5.1 to FCP10.1 when importing media (mp4 or AVCHD) from the hard drive how do I select a range or portion of a clip in the media import window if I do not want to import the entire clip into FCP.  At this point I can select th

  • TV/Monitor 15LV63B RESET?

    I have been given a Television/monitor 15lv63b BUT I cannot use it because 1. I have no original Remote 2. The Buttons on the top of the TV are "Panel Locked" How can I reset the Panel lock or access the menu system to reset any PIN etc. Is there a d

  • Export and Import Users in UCM

    Hi, Does anyone know how to move all users, alias and role definitions from one ucm to another ucm? Thanks.