Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2008, 10:30 PM
Member
 
Join Date: Aug 2008
Posts: 41
Rep Power: 0
hungleon88 is on a distinguished road
Default Problem when insert Date to database(SQL)
When i insert a record with Date to database , it include Month/Day/year and something stupid like 00:00:00
how can we remove 00:00:00 ??
or how can we only insert month/day/year??
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-01-2008, 10:54 PM
Senior Member
 
Join Date: Jun 2008
Posts: 1,407
Rep Power: 3
masijade is on a distinguished road
Default
Change the way you're displaying it?

Use getDate rather than getString?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2008, 10:57 PM
Member
 
Join Date: Aug 2008
Posts: 41
Rep Power: 0
hungleon88 is on a distinguished road
Default
the problem here is i use method getvalueAt of DefaultModelTable , and this method return an Object , so i cannot casting to Date type (
and when i display it, it include 00:00:00
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-02-2008, 08:40 AM
Senior Member
 
Join Date: Jun 2008
Posts: 1,407
Rep Power: 3
masijade is on a distinguished road
Default
Originally Posted by hungleon88 View Post
the problem here is i use method getvalueAt of DefaultModelTable , and this method return an Object ,
And? What do you think a Date is? Cottage Cheese? A Date is also an Object, did you even try to cast it?

Quote:
so i cannot casting to Date type (
And, did you even try?

Quote:
and when i display it, it include 00:00:00
Then what you are printing is either a Date (with no time data) or a String. With a Date, no problem, just cast it, with a String, no problem, use SimpleDateFormat, and parse it. If what you had were actually an instance of "Object" (as you claim) then it would print something like "java.lang.Object@d9f9c3", and not any kind of date/time text.


Show the code you're using (only the relevant parts please, not some novel). And, please, don't tell me you have all sorts of persistence and business logic code tied up in the middle of your GUI code.

Last edited by masijade; 12-02-2008 at 08:56 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-18-2009, 03:05 PM
Member
 
Join Date: Feb 2009
Location: Delhi
Posts: 62
Rep Power: 0
neeraj.singh is on a distinguished road
Default
we have defferent date format methods
you can use that...
for date at backend side
use
to_date(date_var, 'yyyy/mm/dd')
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-29-2009, 01:04 PM
Member
 
Join Date: Apr 2009
Posts: 8
Rep Power: 0
satkk is on a distinguished road
Default re:
I got this code working, try this, dont know whether its the right approach
String datestring= some string(getText() or getParameter())
java.util.Date dt=new java.util.Date();
java.sql.Date dte=new java.sql.Date(dt.getTime());
java.sql.Date dte1=dte.valueOf(datestring);
insert this dte1 to database
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-29-2009, 04:53 PM
OrangeDog's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Cambridge, UK
Posts: 838
Rep Power: 2
OrangeDog is on a distinguished road
Default
That code just adds a random timestamp to the date, which is probably not what you want to do. If your data includes times then include them, of not, leave the time as 00:00:00.

All Date objects include a timestamp. If you don't want to see it, then only print the date part.
__________________
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare date input to database with current date hungleon88 Advanced Java 2 11-25-2008 09:10 AM
how to insert date field read from Excel using JExcel to database saran123 Database 1 10-10-2008 09:47 AM
How to insert java Object in oracle database Thilkumar82 Advanced Java 9 08-13-2008 12:33 PM
Probeleme with insert into database oracle bachtoutou New To Java 0 05-24-2008 12:56 PM
Using PreparedStatement to insert image into database Java Tip Java Tips 0 02-10-2008 12:25 PM


All times are GMT +2. The time now is 01:25 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org