f



Cast from java.util.DATE to java.sql.DATE

DB ORACLE

Calendar stCal = Calendar.getInstance();

stmt.setDate(COLUMN_DATA, stCal.getTime());

doesn't work because setDate method


0
Dom
2/1/2005 11:34:01 AM
comp.lang.java.databases 3049 articles. 0 followers. samyaksulabh (16) is leader. Post Follow

4 Replies
785 Views

Similar Articles

[PageSpeed] 15

Sorry for the first post....

DB ORACLE

Calendar stCal = Calendar.getInstance();
stmt.setDate(COLUMN_DATA, stCal.getTime());

doesn't work because setDate method (int, java.sql.Date) in the type
PreparedStatement is not applicable for the arguments (int, java.util.Date)

If I try with:
stmt.setDate(COLUMN_DATA, (java.sql.Date)stCal.getTime());
I obtain a class cast exception

Any solution? How can I insert a java.util.date obtained from a calendar
object in a Oracle DB (java.sql.Date)?

thanks in advance
Dom


0
Dom
2/1/2005 11:36:16 AM

On 01.02.2005 12:36 Dom wrote:
> 
> Any solution? How can I insert a java.util.date obtained from a calendar
> object in a Oracle DB (java.sql.Date)?
> 

Calendar stCal = Calendar.getInstance();
java.util.Date utlDate = stCal.getTime();
java.sql.Date sqlDate = new java.sql.Date(utlDate.getTime());
stmt.setDate(COLUMN_DATA, sqlDate);

Thomas

0
Thomas
2/1/2005 11:44:47 AM
"Thomas Kellerer" <NNGNVRDSJEBN@spammotel.com> schrieb im Newsbeitrag
news:3698dfF4v06i6U1@individual.net...
>
>
> On 01.02.2005 12:36 Dom wrote:
> >
> > Any solution? How can I insert a java.util.date obtained from a
calendar
> > object in a Oracle DB (java.sql.Date)?
> >
>
> Calendar stCal = Calendar.getInstance();
> java.util.Date utlDate = stCal.getTime();
> java.sql.Date sqlDate = new java.sql.Date(utlDate.getTime());
> stmt.setDate(COLUMN_DATA, sqlDate);

A bit shorter:

Calendar stCal = Calendar.getInstance();
java.sql.Date sqlDate = new java.sql.Date(stCal.getTimeInMillis());
stmt.setDate(COLUMN_DATA, sqlDate);

Kind regards

    robert

0
Robert
2/1/2005 1:48:10 PM
Thanks to all!

Either solution are good.

bye



0
Dom
2/1/2005 2:30:53 PM
Reply:

Similar Artilces:

Convert java.util.Date to java.sql.Date
I convert java.util.Date to java.sql.Date this way:java.util.Date utilDate = new java.util.Date();java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());And then send sqlDate to prepareStatement.ps.setDate(1, sqlDate).But I got the date such as dd-mm-yyyy. And I need also take hours,minutes pm(am).How can I get the Date "dd-mm-yyyy hh:mm a"? Bumsys@gmail.com wrote: > I convert java.util.Date to java.sql.Date this way: > > java.util.Date utilDate = new java.util.Date(); > java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); > > And then send sqlD...

(Again) java.util.Date vs java.sql.Date
Hi there, (Again) Im trying to understand the EXACT difference between java.util.Date vs java.sql.Date. Googling, I can see that this is a very "popular" subject, but I still cannot figure out it exactly. Many writers claim that java.sql.Date only stores the DATE part (yyyy- mm-dd) but not the TIME part (hh:MM:ss) of a Date/Time value, but that I can easily disprove: java.util.Date ud = new java.util.Date(); java.sql.Date sd = new java.sql.Date(ud.getTime()); System.out.println(DateFormatUtils.format(ud, "yyyy-mm-dd hh:MM:ss.SSS")); System.out.println(DateFormatU...

Converting java.util.Date to java.sql.Date
Hello Friends In my program i am using the following codes: Date today = new Date(); log.debug("today is"+today); SimpleDateFormat fmt = new SimpleDateFormat("yyyy-mm-dd"); String todayStr = fmt.format(today); log.debug("todayStr value"+todayStr); java.sql.Date dt = java.sql.Date.valueOf(new String(todayStr)); log.debug("current Dt is:"+dt); The output iam getting is like this: today is Sat Sep 09 19:20:13 IST 2006(from java.util.Date) todayStr value 2006-20-09(from string value) current Dt is: 2007-08-09(from java.sql.Date) So h...

warning: [deprecation] in java.util.Date(java.lang.String) has been deprecated
Dear Java Programmers, When compiling my Java program I get the following warning: "warning: [deprecation] in java.util.Date(java.lang.String) has been deprecated" on for example this statement: new Date("09/23/2003") The code is used to generate the dates on a webpage. Depending on the language of the webpage the generated format is different. For example English (see "Date" and "Choose publication" on the page opened): http://home.scarlet.be/kenya-belgium/list_5_en/a_kenyan_birthday_party_and_a_belgian_birthday_party.html French: http://home.scarlet....

XML-RPC
Hello, I am getting an error "XML-RPC - java.lang.ClassCastException: java.util.Date" when I call the "XmlRpcClient" execute method. I believe the underlying classes are having trouble parsing the result from the time.xmlrpc.com/RPC2:80 XML-RPC service. I apologize that I could not navigate the Apache bug reporting and search system. I hope someone can recognize what is up with this. Thank you in advance for any help, Michael import java.util.Vector; import java.util.Hashtable; import org.apache.xmlrpc.*; public class GetTime { private final static String serv...

Java in Java
Is it possible to download a Java app (applet etc?) and run it inside a desktop Java app? -- Dirk http://www.transcendence.me.uk/ - Transcendence UK http://www.theconsensus.org/ - A UK political party http://www.onetribe.me.uk/wordpress/?cat=5 - Our podcasts on weird stuff Dirk Bruere at NeoPax wrote: > Is it possible to download a Java app (applet etc?) and run it inside a > desktop Java app? > Quite likely, but you won't necessarily get the same security model, unless you were careful about it. -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/&g...

Java Java
Have my first Open Source Linux Java Project. Working on a second right now. Coming out with a distro called OPEN*WINDOWS. It will be at www.black-and-company.com tab wrote: > Have my first Open Source Linux Java Project. > Working on a second right now. > > Coming out with a distro called OPEN*WINDOWS. > > It will be at www.black-and-company.com > Wasn't that the whole point of Lindows? Oh, right, we didn't care for that either. tab wrote: > Have my first Open Source Linux Java Project. > Working on a second right now. > > Coming out with a ...

java.lang vs java.util
Surprising to see something defined in java.lang <http://developer.android.com/reference/java/lang/Iterable.html> depend on something defined in java.util <http://developer.android.com/reference/java/util/Iterator.html>. Surely the hierarchy should go the other way? On 4/1/2011 9:11 PM, Lawrence D'Oliveiro wrote: > Surprising to see something defined in java.lang > <http://developer.android.com/reference/java/lang/Iterable.html> depend on > something defined in java.util > <http://developer.android.com/reference/java/util/Iterator.html>. > > Surely the hierarchy should go the other way? I think Iterable may make it into java.lang because of its significance in the foreach statement. Patricia On 04/02/2011 12:23 AM, Patricia Shanahan wrote: > On 4/1/2011 9:11 PM, Lawrence D'Oliveiro wrote: >> Surprising to see something defined in java.lang >> <http://developer.android.com/reference/java/lang/Iterable.html> depend on >> something defined in java.util >> <http://developer.android.com/reference/java/util/Iterator.html>. >> >> Surely the hierarchy should go the other way? Not if it wants to be consistent with http://download.oracle.com/javase/6/docs/api/ don't'cha think? And the so-called "hierarchy" of java.util and java.lang is that they are equal. The language reserves for itself the entire panoply of java.* and javax.* packages. > I think It...

java.sql.Date returning wrong date
Hi can you assist me in finding the root cause of this problem. I amconverting a simple date of "2007-04-20" to SQL date. However forsome reason the conversion is not working. It seems to be defaultingtoo 2007-01-20. Hmm.. perhaps its the getTime() not returning thecorrect number of milliseconds since January 1, 1970. Not sure.Anyway would appreciate a secound pair of eyes on this one. Thanksimport java.sql.Date;import java.text.ParseException;import java.text.SimpleDateFormat;//The codepublic class Testing { public static void main(String[] args) { try { Simpl...

Oracle 10g returns DATE as java.sql.Date?
I noticed that Oracle 10g XE, with the ojdbc14.jar JDBC driver, returns DATE columns as java.sql.Date valuess. That surprised me, because the ResultSetMetaData claims the column's Java type is java.sql.Timestamp -- which would make more sense since DATE columns contain date *and* time information, just just date. I seem to remember that Oracle 8i did return java.sql.Timestamp for DATE columns. Did they change this, or am I just misremembering? Is there a way to get the driver to return java.sql.Timestamp? thomas_okken@hotmail.com wrote: > I noticed that Oracle 10g XE, with the ojdb...

Java (new Date()).getTime()
Hello, I tried to retrieve a timestamp from my database independent from the local TZ environment variable. The ResultSet.getTimestamp(...).getTime() method should return the number of seconds after "1.1.1970 GMT" like (new Date()).getTime() . Is there any timestamp (current, local, sys, ...) to get the correct time? Thanks in advance Jörg -------------------------------------------------------- export TZ=... run : PreparedStatement s = c.prepareStatement( "SELECT ?????????? FROM dual"); ResultSet rs = s.executeQuery(); rs.next(); t3 = rs.getTimestamp(1,java.util.Calendar.getInstance()); System.out.println( "Timestamp-Error:" +rs.getTimestamp(1).getTime()-(new Date().getTime()); rs.close() ; s.close() ; On May 22, 4:34 pm, Joerg Weule <jwe...@arcor.de> wrote: > Hello, > > I tried to retrieve a timestamp from my database independent from the > local TZ environment variable. The ResultSet.getTimestamp(...).getTime() > method should return the number of seconds after "1.1.1970 GMT" like > (new Date()).getTime() . > > Is there any timestamp (current, local, sys, ...) to get the correct time? > > Thanks in advance > > J=F6rg > > -------------------------------------------------------- > export TZ=3D... > > run : > > PreparedStatement s =3D c.prepareStatement( > "SELECT ?????????? FROM dual"...

Java Date and Excel Date
Hi, In Excel, the date represents the number of days since Jan/1/1990, with the number 1 representing that date. May/1/2006 is represented by . So the following ought to convert that number to a java date: GregorianCalendar gc = new GregorianCalendar(1900, Calendar.JANUARY, 1); gc.setTimeInMillis(gc.getTimeInMillis()+ (38838L-1)*24*60*60*1000); System.out.println(gc.getTime()); But I get Tue May 02 01:00:00 EDT 2006 Am I doing something wrong or does Excel count days wrong? Many thanks in advance! Aaron Fude aaronfude@gmail.com wrote: > In Excel, the date represents the number o...

CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean
Hello, I have discovered a hidden error. My project was working for awhile, but then I started to get the below error. My error comes from the fact that I'm using a checkbox in a jtable, and I'm using the below "getColumnClass". Thank you, compile: run: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:5412) at javax.swing.JTable.prepareRenderer(JTable.java:5735) at javax.swing.plaf.basic.BasicTableU...

java.sql.Date truncated when written to DB. How to obtain full date?
I'm trying to write a java.sql.Date to a database and the minutes/ seconds etc. are not being written. I've seen and tested many examples found via searches and still have come up with nothing. Here's what I have: java.sql.Date formation - recommended forms: java.sql.Date entryDttm = new java.sql.Date(System.currentTimeMillis()); OR java.sql.Date entryDttm = new java.sql.Date(new java.util.Date().getTime()); // prepared statement insert pstmt.setDate(1, entryDttm); // what is written to database 2007-02-07 12:00:00.000 // what needs to be written 2007-02-08 09:37:25.793 The fie...

java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460)
Hi All I am having the torque3.1.jar and postgresql-7.4. I have compiled the new jdbc driver called as postgresql.jar and have placed it in the lib directory from where the ant scripts catch the jars. Whenever i try to access through torque gestList = BaseGestlistPeer.doSelect(new Criteria()); this error arises java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460) at org.postgresql.jdbc2.ResultSet.toTimestamp(ResultSet.java:1653) at org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java...

java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace: java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException at COM.ibm.db2.jdbc.app.DB2Driver.SQLAllocEnv(Native Method) at COM.ibm.db2.jdbc.app.DB2Driver.<init>(DB2Driver.java:245) at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(DB2Driver.java:130) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Cla...

java.sql.SQLException: java.sql.Time
I get the following error message... java.sql.SQLException: Value '00:00:00 can not be represented as java.sql.Time >From the following SQL call... SELECT COUNT(pageurl) AS PageCount, pageurl, MAX(datetime) AS LastAccess, SUM(VisitLength) as TotalVisitLength, VisitLength, RecordNum, SUM(CASE WHEN VisitLength IS NULL THEN 1 ELSE 0 END) AS NullVisits FROM clubvisits WHERE groupid = #clubid# GROUP BY pageurl ORDER BY #OrderKey# I am using ColdFusion 7 on MySQL 4.1.12a. I'm not a Java programmer - I don't know any Java, but ColdFusion acts essentially as a script layer to J2EE, so for some reason it's throwing a Java error. I'm especially stuck, because I need to resolve this without programming any Java, and the Adobe forums for ColdFusion and MySQL groups are no help. The error refers to the "VisitLength" field which is a "time" data type in the database. In the MySQL documentation, it says that 00:00:00 is allowable for time (http://dev.mysql.com/doc/refman/4.1/ en/ time.html). So my question is, why is this error coming up if it's an allowable value? And is there anything I can do? >So my question is, why is this error coming up if it's an allowable >value? And is there anything I can do? one way is to store the values as raw ints or longs as far as SQL is concerned. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com <mehatespam1085@yahoo.com> wrote... ...

java.sql.SQLException: java.sql.Time
I get the following error message... java.sql.SQLException: Value '00:00:00 can not be represented as java.sql.Time >From the following SQL call... SELECT COUNT(pageurl) AS PageCount, pageurl, MAX(datetime) AS LastAccess, SUM(VisitLength) as TotalVisitLength, VisitLength, RecordNum, SUM(CASE WHEN VisitLength IS NULL THEN 1 ELSE 0 END) AS NullVisits FROM clubvisits WHERE groupid = #clubid# GROUP BY pageurl ORDER BY #OrderKey# I am using ColdFusion 7 (not my choice - don't laugh) on MySQL 4.1.12a. The error refers to the "VisitLength" field which is a "time" da...

java.util.Date
I'm trying to extract the day, month, and year fields from a java.util.Date object in Java 1.4. can somebody give me some pointers? Thanks. -james "james tsao" <jtsao@go.com> wrote in message news:8c426184.0404221049.644ed860@posting.google.com... > I'm trying to extract the day, month, and year fields from a > java.util.Date object in Java 1.4. > can somebody give me some pointers? > Thanks. > -james Look at Calendar. Silvio Bierman jtsao@go.com (james tsao) wrote: > I'm trying to extract the day, month, and year fields ...

how do you update a java.sql.date type in an ms access database
when i update a row in an access database the date field does not update to the correct date it brings up some funny date which i dont know where it comes from. Below is the method i use to update. maybe the date types are not compatable? thanks in advance, public static void bookIN(int custID, int rNumber,java.sql.Date bkInDate ){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String filename = "hotelDB.mdb"; String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; database+=...

Abandon java.util.Hashtable and java.util.Vector
Abandon java.util.Hashtable and java.util.Vector. Use other java.util.Map and java.util.List implementations instead, such as java.util.HashMap and java.util.ArrayList, respectively. While you're at it, don't use java.util.Enumeration; stick with java.util.Iterator. -- Lew On Mar 31, 8:24 pm, Lew <l...@nospam.lewscanon.com> wrote: > Abandon java.util.Hashtable and java.util.Vector. Use other java.util.Map and > java.util.List implementations instead, such as java.util.HashMap and > java.util.ArrayList, respectively. Tell that the m*th*f*ck*s at Sun wh...

Loading a large dataset from a database-- java.lang.OutOfMemoryError: Java heap space
Dear all, While trying to load a big table, I received the following error. Is there any way to circumvent this problem without doing additional programming? Thanks you help, Kirill Andreev ??? Java exception occurred: java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Unknown Source) at java.util.Arrays.copyOf(Unknown Source) at java.util.Vector.ensureCapacityHelper(Unknown Source) at java.util.Vector.addElement(Unknown Source) at com.mathworks.toolbox.database.fetchTheData.dataFetch(fetchTheData.java: 740) Error in ==> cursor....

Poll: Is a Java Method an Instance of the Java Class java.lang.reflect.Method? Please reply with YES or NO.
Hi, Poll: Is a Java Method an Instance of the Java Class java.lang.reflect.Method? Please put YES or NO as the first word in your reply. Add comments after it if you wish. I'll make a YES/NO count after some time. Kind regards, Paka Paka Small wrote: > Poll: Is a Java Method an Instance of the Java Class > java.lang.reflect.Method? It's not subject to vote. It's defined by the language. You might as well ask, "Is 'int' a primitive or a reference type?". Your vote will not change reality. > Please put YES or NO as the first word in your reply. Add c...

Java Date class that performs date calculations?
I need some sample code that will: a) establish the current payment Date b)determine last payment Date and c) calculate the elasped days between the two dates. Any help would be appreciated! i dont believe anyone can answer a or b without first seeing the specifications. here is a starting point for c) http://scienceworld.wolfram.com/astronomy/GregorianCalendar.html wxwindows has some sample code but it is for c++. maybe someone can let you know a similar set of classes done in java like wxwindows. hope this helps, jim "GRR" <bat2win@hotmail.com> wrote in message news:...

Web resources about - Cast from java.util.DATE to java.sql.DATE - comp.lang.java.databases

Cast Irony
@castirony iOS and web developer in Portland, OR

Cast-iron cookware - Wikipedia, the free encyclopedia
Cast iron cookware has excellent heat retention properties and can be produced and formed with a relatively low level of technology. Seasoning ...

Facebook Weekly Highlights Brings You Cast Of ‘Star Wars: Episode VII’
... features photos and videos posted to the social network by celebrities and athletes. This week’s edition featured this photo of the cast of ...

VIDEO: Tradition! FIDDLER ON THE ROOF Cast Joins Stephen Colbert to Perform Classics
Broadway World VIDEO: Tradition! FIDDLER ON THE ROOF Cast Joins Stephen Colbert to Perform Classics Broadway World When a family accidently ...

The Real O'Neals Review: ABC's New Comedy Boasts A Great Cast And Lots Of Uncomfortable Moments
Cinema Blend The Real O'Neals Review: ABC's New Comedy Boasts A Great Cast And Lots Of Uncomfortable Moments Cinema Blend American audiences ...

ABC’s ‘Notorious’ Pilot Casts Kate Jennings Grant & J. August Richards; Gloria Garayua Joins ‘The Fluffy ...
Kate Jennings Grant ( Love & Other Drugs) and Girlfriends’ Guide To Divorce’ s J. August Richards have been cast opposite Daniel Sunjata and ...

Miss Colombia Ariadna Gutierrez Cast in Vin Diesel's 'xXx' Sequel After Miss Universe Mix-Up
Miss Colombia Ariadna Gutierrez Cast in Vin Diesel's 'xXx' Sequel After Miss Universe Mix-Up

'RHONY' Cast Mate Sonja Morgan Discusses Her International Fashion Lifestyle Brand
From a production company to a toaster oven to a fashion line to a Prosecco, 'The Real Housewives of New York' cast mate Sonja Morgan has no ...

Stephen Colbert Sings "Tradition" and "Matchmaker" With Broadway's 'Fiddler on the Roof' Cast
Hollywood Reporter Stephen Colbert Sings "Tradition" and "Matchmaker" With Broadway's 'Fiddler on the Roof' Cast Hollywood Reporter Stephen ...

‘House Of Cards’ Says Goodbye To Creator Beau Willimon, Cast Claims Frank Underwood Will Have ‘More Bloodshed’ ...
... last for the show’s creator, Beau Willimon. While Willimon did not make an appearance at the red carpet premiere, several members of the cast ...

Resources last updated: 3/2/2016 8:18:11 PM