Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Date type typecasting
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ravi
Date type typecasting
1 Answer(s)      6 years and 10 months ago
Posted in : Java Beginners


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


Advertisement
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
Advertisements
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
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
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
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... type. First of all you need a date that needs to be converted...() method is used to convert the given date into a long type. This method
MySQL Column Type Database
of column in MySQL . MySQL supports the numeric type , Date and time type, and String...,' .....) 1 to 8 Byte 0 64 MySQL Store the Date and Time Type... MySQL Column Type Database     
Mysql Alter Data Type
Mysql Alter Data Type       Mysql  Alter Date Type is used to modify or change the Column... on 'Mysql Alter Date Type'.To understand this example we create a table
date
date   how to insert date in database? i need coding
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  i want difference between the date entered in a jtextfield 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  can u tell me how to calculate difference between a user provided date and the system date in java
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
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.  1- index.jsp   <html> <head> <title>Date
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
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
Mysql date field
'employee2' with field name and date respectively. The data type used for date is date data type.   Query for creating date field:- CREATE TABLE... into the table 'employee2'.The format of date date type is 'YYYY-MM-DD'. mysql>
Convert Date to String
Convert Date to String       In this section, you will learn to convert a date into string type. The java.util package provides the functionality to convert
type casting
type casting  what is type casting
Type casting
Type casting  how to type cast a string value to byte array
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
type casting
List (object type) <Object> totalList(int pi){ try{ Query q...type casting  <--bean class-->method calllist is of object type...){ return null; } how to type cast object type to entity type
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
type casting
type casting  int n=20; n=sizeof((char)(float)n); what is n value
data type
data type  which data type is used to store video file in mysql databse
 

 

 

DMCA.com