This content has been marked as final. Show 8 replies
GMX750 wrote:You don't need to do that. Chances are your database's DATE, TIME, and DATETIME fields don't even have formats, just as Java's Dates don't.
can someone help? i want the date to correspond to the variable format on my database (DATETIME (yyyy-mm-dd))
If you're stating with a String, create an appropriate SimpleDateFormat object to parse() it into a java.util.Date.
Once you have a java.util.Date, use the appropriate method(s) and constructor(s) to create a java.sql.Date or java.sql.Timestamp.
Then use PreparedStatement's setDate() or setTimestamp() method.
Timeout! Shouldn't your table column be of a type such as DATE or TIMESTAMP, not NVARCHAR?
edit: too slow. Listen to jverd.
Actually, stop and learn Java first. You're trying to do something non-trivial (database access) when you can't do something trivial (call a method). It's like you're trying to perform surgery to remove an appendix and you're holding up the scalpel and saying "which end do I use?"
edit #2: too slow, again.
GMX750 wrote:If you don't know the difference between static and non-static methods, or how to instantiate an object, you're not ready to be messing with JDBC yet. Sorry if that sounds harsh, but it's the truth. If you keep trying to go down this path without getting a handle on the fundamentals, you're just setting yourself up for more frustration and a poor excuse for an education.
OK, like this?:
df = DateFormat.parse(data.getText());
i did this, but the IDE says the same thing
Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806].
GMX750 wrote:Seriously. Go back to the basics. You're missing a lot of really fundamental stuff that would make that not a mystery at all.
if i do this DateFormat df = new DateFormat(); it doesnt instanciate it because DateFormat is not instanciateable, at least that's what Eclipse says....
[Formatting a Date Using a Custom Format|http://www.javaalmanac.com/egs/java.text/FormatDate.html]
[Parsing a Date Using a Custom Format|http://www.javaalmanac.com/egs/java.text/ParseDate.html]