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



Home Answers Viewqa Java-Beginners Date type typecasting

Have Programming Question? Ask it here!
 
 
 


Ravi
Date type typecasting
1 Answer(s)      6 years and 6 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...); } Datedate=newDate(); 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
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>
type casting
type casting  what is type casting
Type casting
Type casting  how to type cast a string value to byte array
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
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
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
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
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 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
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  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 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 - 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
PHP Type Juggling
Type Juggling In PHP: Unlike other programming languages like C,C++ and Java... a float value to a variable then it becomes float type and if we assign... of implicit typecasting is if we add two integer variables then the result is integer
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
coding for re-type password
coding for re-type password  coding for re-type password
Document Type Definition
Document Type Definition  What is Document Type Definition
fastest type of JDBC driver
fastest type of JDBC driver  What is the fastest type of JDBC driver
Reference type Vs Object type. - Java Beginners
Reference type Vs Object type.  Can anyone explain the exact... or object type variable which may reference a Book object or an object of any... of Employee Class 'Employee' would be the REFERENCE TYPE and Class
date convertion
date convertion  How to convert the string date format 23/11/2009 to original date format in asp.net
Fastest type of JDBC Driver
Fastest type of JDBC Driver  hello, What is the fastest type of JDBC driver?   hii, Type 4 is the fastest JDBC driver
Mysql Date from Date
Mysql Date from Date       Mysql  Date from Date Time in Mysql return the Current  date. Understand with Example The Tutorial illustrate an example from 'DateTime
Java type casting
Java type casting  What is Downcasting
Advertisements
 

 

 

DMCA.com