Date type typecasting

Date type typecasting

Can i type cast Date object of java.util.* to java.sql.* Date Object? if so how? Refer to the following url http... This requires more than a typecast. You need to tell the system what format the date

View Answers

March 5, 2008 at 4:30 AM

Refer to the following url

http://forum.java.sun.com/thread.jspa?threadID=679914&messageID=3965390

This requires more than a typecast. You need to tell the system what format the date is in. To do this you use a DateFormat object. Usually, when reading dates, you use a SimpleDateFormat, which allows you to supply a pattern string, indicating how the variious components are organised. Date.parse gives you a result of type java.util.Date.

Unfortunately for JDBC you need a java.sql.Date object, so you need another stage of coversion.

You should study the Javadocs for DateFormat and SimpleDate format.

But basically you do something like this:

DataFormat df = new SimpleDateFormat("dd/MM/yyyy");
try {
java.util.Date date = df.parse(dateStr);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
} catch(ParseException e) {
.. deail with invalid date format here
}









Related Tutorials/Questions & Answers:
Date type typecasting - Java Beginners
Date type typecasting  Can i type cast Date object of java.util.* to java.sql.* Date Object? if so how? Refer to the following url http... the system what format the date is in. To do this you use a DateFormat object
Mysql Date Type
Mysql Date Type       Mysql Date Type is used to show the date in "yyyy-mm-dd" format.The Date Type is used when you want to display the date but not time. Understand
Advertisements
Typecasting
Typecasting
Get date data type from table
GET DATE DATA TYPE FROM TABLE In this example , we will get "Date" data type from a table of "Mysql" database and it also display...);             }         Date date = new Date();         System.out.println("Today's
Double To Int Without TypeCasting
Double To Int Without TypeCasting  How to convert Double to Int without using typecasting?   class ConvertDoubleToInt { public static void main(String[] args) { double d=25.5; int num=new
Criteria: Greater To Equal criteria for Date type
Criteria: Greater To Equal criteria for Date type In this Example, We...; date type value to the given within the table. Here is the simple Example code...", new Date())); List list = crit.list(); Iterator itr = list.iterator
Convert Date to Long
to convert a date type into a long type.  Description of program... a date into a long type. First of all you need a date that needs.... The getTime() method is used to convert the given date into a long type
date
database table name birthday (DOB date); dob with DATE data type in database while...=d.getTime(); java.sql.Date date = new java.sql.Date(t); try { System.out.println(date); Class.forName("oracle.jdbc.OracleDriver"); con
date
date   how to insert date in database? i need coding
MySQL Column Type Database
of column in MySQL . MySQL supports the numeric type , Date and time type, and String type (char) database. MySQL Numeric type and String type Database :ADS... MySQL Column Type Database     
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
Mysql Alter Data Type
Mysql Alter Data Type       Mysql  Alter Date Type is used to modify or change the Column... cover an example on 'Mysql Alter Date Type'.To understand this example we
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
DATE
DATE  I have the following as my known parameter Effective Date... of calcultion starts My question is how to find the date of Thursday This cycle... the date of all the thursdays of the given year. import java.util.*; import
struts2.2.1 date Format example
struts2.2.1 date Format example. In this example, We will discuss about the different type of date format using struts2.2.1. Directory structure of example...; <title>Date Format Example</title> </head>ADS_TO_REPLACE_2
Mysql date field
a table 'employee2' with field name and date respectively. The data type used for date is date data type.   Query for creating date field... into add the records value into the table 'employee2'.The format of date date type
Convert Date to String
to convert the date into a string type. Firstly, you need to pass a date ... Convert Date to String       In this section, you will learn to convert a date into string
type casting - Java Beginners
type casting and conversion  I am beginner and my query is Importance of type casting and conversion  Hi friend,public class TypeCasting{ public static void main(String[] args){ boolean t = true; byte b = 2; short s
type casting
type casting  what is type casting
Type casting
Type casting  how to type cast a string value to byte array
type casting
type casting  <--bean class-->method calllist is of object type... List (object type) <Object> totalList(int pi){ (adsbygoogle = window.adsbygoogle || []).push({}); try{ Query q= em.createQuery
type mismatch
type mismatch  Statement s= con.createStatement(); this line gives error of "type mismatch" I am using eclips nd new to servlet nd JDBC, Please help me, Thank you
data type
data type  which data type is used to store video file in mysql databse
type casting
type casting  int n=20; n=sizeof((char)(float)n); what is n value
hibernate criteria date
;. In This example we search for greater to equal  date type value...hibernate criteria Date In this Tutorial, We will discuss about hibernate...(Restrictions.ge("UserDOB", new Date())); List list = crit.list
php date function - Date Calendar
: 1960-12-02 (type is date ) In PHP : $dob= " 1960-12-02...php date function  Hi, I am new to PHP. I am trying to get date from database. But, every time the date under 1970, it changes to 1970. Im
Date prorblem
Date prorblem  HI all, i have date comming from one text file into string filed in java code. once the date is available in filed ( of type String... to insert the date into oracle DB. my code is as below: String DATEADDED
date between
of my fields is date_, and the type of the field is DateTime. When I want to select records between 2 dates, I use this query: Select * from table1 Where date...date between  Hi Iââ?¬â?¢ve wrote a program by Delphi 7, Iââ?¬â?¢ve
date format - Date Calendar
date format  how to convert dd-mmm-yyyy date format to gregorian... to convert date to calender. import java.util.*; import java.text.*; public...="19-Sep-2008"; DateFormat format ; Date date ; format = new
data type
data type  what are the date types in the java and vb.net? what is the difference between java and vb.net?   Hi Friend, java data types... Single Double Decimal Char Boolean Date String Object
Date format - Date Calendar
Date format  please convert dd-mmm-yy date format to gregorian calendar date format.  Hi friend, Code related your Problem: import...]); Calendar calendar = new GregorianCalendar(pdt); Date time = new Date
date - Date Calendar
date   hi, sir i am doing student details project in swing but i am not getting current date in jtextfield in date it is giving ambigious error... label=new JLabel("Current Date: "); JTextField text=new JTextField(15
Date Formay - Date Calendar
Date Formay  Sir, How to comapare two different date format in java.  Hi friend, Code to compare two different date import...)) System.out.print("Current date(" + new SimpleDateFormat("dd/MM/yyyy"). format
Date format - Date Calendar
Date format  Hi All, I am getting a date from database as a format 2010-15-07.I need to change it to 07/15/2010 and display it on my date field.Every time i need to check the format of the date field and make sure the correct
Date limit on Dojo Date picker - Date Calendar
Date limit on Dojo Date picker  Hi all, I am using dojo for date picker in my project. When user click on date text box, date picker will pop up. Using that component user can select date. Now I trying something different. I
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP
date convertion
date convertion  How to convert the string date format 23/11/2009 to original date format in asp.net
Getting Computer Date in java
but this.. String strDate = new Date(); I get this server error, "The type Date is ambiguous". I've also tried Date date = new Date(); ... but it get's the same error...Getting Computer Date in java  Hi , I want to get the PC Date
Date auto format
Date auto format  Hi, I have jsp page and Date field with input type. Requirement is, if we enter date as MMDDYY or MMDDYYYY and clicking the tab the date(MMDDYY or MMDDYYYY) have to auto format to MM/DD/YYYY. could you please
Mysql Date from Date
Mysql Date from Date       Mysql  Date from Date Time in Mysql return the Current  date. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate
Java Date
Java Date  Hi, What is the API for Date management in Java? How use the Java Date API for manipulating date object in Java? Provide some... of API for working with date and time objects in Java. You can also use third
Date Picker
Date Picker  "I want to set default calendar date when using datepicker. This date means auto-loaded date when the calendar appears. The default date is the current date. I want to change it. How could I do
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012

Ads