Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2007

Tip: Looking for answers? Try searching our database.

Prepared Statement Joda Time

Thread view: 
Jim Bailey - 14 Feb 2007 14:45 GMT
Knowing I'd be manipulating some dates/times, I thought I'd try the Joda
Time classes form SourceForge in this app.  However, it seems to be
complicating, rather than aiding so far. It's a Swing app with SqlServer DB.
BTW: The statement itself  works fine if i just pass a literal string for a
date instead of the "?".

private String autoQuery = "select 3, isnull(count(*), 0) " +
           "from  a_table " +
           "where source_type = 4 and fk_status = 3 " +
           "and create_date > ?";

PreparedStatement stmt = connection.prepareStatement(autoQuery);
//  variable dt is created from org.joda.time.DateTime and passed into this
method
stmt.setDate(1, dt);

the setDate method doesn't like the Joda DateTime type so i tried to
convert:

java.sql.Date jd = new java.sql.Date(dt.toDateTime());  // supposed to
convert to JDK type

but this constructor still doesn't like the type.  Plus - I found that
java.sql.Date zeros the time, and i need the seconds

There should be an easier way to do this that I'm missing somehow. Can
anyone be of assistance ?

jim
joeNOSPAM@BEA.com - 14 Feb 2007 16:31 GMT
> Knowing I'd be manipulating some dates/times, I thought I'd try the Joda
> Time classes form SourceForge in this app.  However, it seems to be
[quoted text clipped - 25 lines]
>
> jim

You should create and use a java.sql.Timestamp, not a java.sql.Date.
By spec, the java.sql.Date has no time element.
Joe Weinstein at BEA Systems


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.