Hello. Has anyone had to write a Date type to a SQL table? The Date type includes both the Date and Time. What SQL data type do I use? Or is this best handled by using strings?
I have tried writing Date type to SQL data types datetime, smalldatetime and timestamp with no joy. I have successfully written to int, char and varchar data types so there is something going wrong with the Date type write. Log shows standard SQL error message.
This SQL link may also help you understand the SQL datetime opaque type.
Eddie, this is a standard Java/SQL question.
If you make the Jave Date class write the date and time as a string in exactly the correct form you can hand it to SQL and it will convert the string and store the value in a column whose type is SQL datetime.
CREATE TABLE #dts(c1 char(1), dt datetime)
INSERT INTO #dts (c1, dt) VALUES('a', '20090124 08:43:31')
Look up on-line refs to T-SQL to ensure what I say is correct.
So all you need to do is create some Java code that will make a string like the above from your Date class. Attached is some verbose Java that you can make into a .class file and execute it at the command line to test the code. Once you are familiar with the solution, borrow the bits you need into the expression editor.