getting date value from MS SQL Server 2000

Hi,Can anyone show me how to get date value from MS SQL Server 2000? Or i need to create a Date class and use setTime() method to do so.Thanks for any help.
[177 byte] By [marcalena] at [2007-9-26 3:40:43]
# 1
String sql = "select mydate from mytable";ResultSet rs= ...java.sql.Timestamp d = rs.getTimestamp(1);java.util.Date dd = (d != null) ? new java.util.Date(d.getTime()) : null;
jschell at 2007-6-29 12:16:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

This has always been my favorite way of doing it :

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

ResultSet rs=....

java.util.Date d = sdf.parse(rs.getString(1));

The reason for the getString is because the time always get chopped off if you use getDate(). And I didn't want to use a getTimestamp() because I just wanted to deal with Date objects.

tlarason at 2007-6-29 12:16:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Hi,

I think i have made a wrong explanation for my query.My query is i would like to insert date value into MS SQL,but i don't want to key in value.For instance, i don't want to setString() or setTimeStamp(),i just want to automatically get the date value from MS SQL and insert it into table.Is it possible? Or i have to use method to do so.Sorry for my mistake.

marcalena at 2007-6-29 12:16:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Like this.... insert into mytable (myid, mytime)values('3', GETDATE())
jschell at 2007-6-29 12:16:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
> And I didn't want to use a getTimestamp() > because I just wanted to deal with Date objects. Huh? java.sql.Timestamp is a date object. Its parent is java.util.Date.
jschell at 2007-6-29 12:16:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
hi,If i don't want to insert any date value into DB table, is it possible to retrieve date value from DB? I want MS SQL Server to generate date value for me, is it possible?
marcalena at 2007-6-29 12:16:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
I can't remember for sure but tryselect GETDATE()
jschell at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

Hello guys...

well may seem pretty funny... but my problem is what should i put in

DriverManager.getConnection(" WHAT SHOULD COME HERE.. !!! " )

I'm usind sun's driver to connect .. and not using any third party Bridge... i have never worked with MSSQL..( only worked with Oracle and MySql...!!!! )

please tell me what should be there in the expression above... it's pretty urgent...

and can anyone tell me about sending a mail from an applet... like an HTML mail... like on " SUBMIT " i want a mail to go out at a particular address... the mail's content are the values of the fields...and i would like to send it from an applet..

hope someone can helpe me on this... !!

thanks ..many a thanks...

premal

genghiz at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
genghiz said >well may seem pretty funny... but my problem is > what should i put in ...What does that have to do with this thread?
jschell at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10
yeh.... nothing to do with this thread...thought had created a new thread when posted this... !!!hope u don't find this one " Out of thread " too... !!
genghiz at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 11
> > What does that have to do with this thread?> > >
genghiz at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 12
> What does that have to do with this thread?> > > yeh.. know that is not exactly the same thing.. thought that had created a new thread when posting this.. !!hope u don't find this " out of thread " too...!!
genghiz at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 13

Hi,

I used JOptionPane.showInputDialog to let me insert the date value for my application,but after inserting into DB, i found that the date value is 1/1/1900 when i used datatime data type and the value is 0 when i used varchar data type,why?Is it because i didn't insert any value so MS SQL automatically put a value for me?

marcalena at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 14
A value of "0" is a valid date.If you don't want a date at all then you need to insert a null.
jschell at 2007-6-29 12:16:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 15
hi,Sorry i think u get the wrong meaning of me. I mean i use JOptionPane.inputShowDialog to let me fill in date value,but after filling in,i just get 1/1/1900 in DB.For instance i fill in 19/08/2001 but when i check my database,i just get 1/1/1900.Can you explain?
marcalena at 2007-7-1 9:25:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 16
Have you tried printing the value before you insert it into the database? That way you know if the problem is in your SQL or the way you translate it from the gui.
jschell at 2007-7-1 9:25:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 17

Hi,

I didn't try the printing that you mentioned,but last time i also used the same JOptionPane.showInputDialog method to insert date value,but the value that i inserted was defined as January,february...(string).but now i would like to try actual date value.

Can you please tell me do i need to create a date class?I set the value of date object first,then i get from the class.If yes,how do i write that class?

Really thanks for your help.

marcalena at 2007-7-1 9:25:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...