× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I agree (again) that using strings is not ideal. Your guess is more or
less accurate. I'm using a set of classes for database access that does
not currently provide for SQL date objects.

Thanks,
Todd





"James Perkins"
<jrperkinsjr@gmai
l.com> To
Sent by: "Java Programming on and around the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>
cc

2008-11-05 17:14 Subject
Re: JDBC date insert

Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.com>






I think you might need to explain why your are restricted strings. Treating
everything as a string is not very OO and is hard to deal with when using
an
OO language.

My guess is that you are sending "insert into myfile (cmdate, cmtime)
values(cast('11/5/2008' as date),cast('4:02:04' as time))" as a string to
another class to execute the SQL statement?

If that's the case I would think using a Date object and the
SimpleDateFormat would give you what you need.


James R. Perkins


On Wed, Nov 5, 2008 at 1:38 PM, <TAllen@xxxxxxxxxxxx> wrote:

The issue I have is that I am restricted to using strings so I cannot use
a
Date type as in your example. See my last reply. I cannot use a
PreparedStatement sinc I am working with an existing set of classes.

Thanks,
Todd





"Joe Sam Shirah"
<joe_sam@bellsout
h.net> To
Sent by: "Java Programming on and around the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>
cc

2008-11-05 16:07
Subject
Re: JDBC date insert

Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.com>







Hi Todd,

Well, Alan wants you to use an entirely separate piece of software
that

will only work on the AS/400. I don't know if you looked at the link I
sent, but to me, the pertinent part is "That will work on any database
with

a compliant driver." I will grant that valueOf() wants a specific
format,
but you aren't tied to anything the AS/400 or other platform has.
Second,
it's the standard Java API, no driver properties involved, and is a one
liner after any formatting. Trivial example of one way:

String sMyDate = "2010-01-31";
ps.setDate( java.sql.Date.valueOf( sMyDate ) );


If those arguments make sense to you, use it. If not, find a way that
does. You're certainly not going to hurt my feelings.


Joe Sam

Joe Sam Shirah - http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum: http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International? http://www.jguru.com/faq/I18N
Que Java400? http://www.jguru.com/faq/Java400

----- Original Message -----
From: <TAllen@xxxxxxxxxxxx>
To: "Java Programming on and around the iSeries / AS400"
<java400-l@xxxxxxxxxxxx>
Sent: Wednesday, November 05, 2008 2:42 PM
Subject: Re: JDBC date insert


I also agree. However, I am restricted to using strings right now. I
cannot use a date object. Also, I do not have access to the driver
properties.

Inserting a date in all different formats (e.g. 11/4/2008, 2008-11-4)
works
fine from the SQL green screen. All fail using JDBC. The JDBC insert
seems to want the date in perfect MM/DD/YYYY format with leading zeros,
as
is set for the system date format. It seems the only option is to
modify
the string to be in MM/DD/YYY format . I don't forsee the system date
format changing but I'd rather not tie myself to it. Is there another
way?

Thanks,
Todd





"Joe Sam Shirah"
<joe_sam@bellsout
h.net>
To
Sent by: "Java Programming on and around
the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>

cc

2008-11-05 12:07
Subject
Re: JDBC date insert

Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.com>







Hi Todd,

I agree with both Paul and James.

If you need to specify values other than the current date and time,
use
the valueOf() methods of java.sql.Date, java.sql.Time,
java.sql.Timestamp
with the values in standard escape syntax. That will work on any
database
with a compliant driver.

See:

http://www.jguru.com/faq/view.jsp?EID=422110

under " The second method..." for an example, and review the javadocs.


Joe Sam

Joe Sam Shirah - http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum: http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International? http://www.jguru.com/faq/I18N
Que Java400? http://www.jguru.com/faq/Java400

----- Original Message -----
From: <TAllen@xxxxxxxxxxxx>
To: "Java Programming on and around the iSeries / AS400"
<java400-l@xxxxxxxxxxxx>
Sent: Wednesday, November 05, 2008 11:42 AM
Subject: RE: JDBC date insert


It is a prepared statement but I was trying to keep the Java code
simple
by
dealing with only strings. It seems I'll need to do the conversion in
the
Java code rather than in the SQL statement.

Thanks,
Todd





"Clapham, Paul"
<pclapham@core-ma
rk.com>
To
Sent by: "Java Programming on and around
the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>

cc

2008-11-05 11:25
Subject
RE: JDBC date insert

Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.com>






Well, don't do it that way. Just use a PreparedStatement. It takes
care
of all those annoying details on your behalf.

java.util.Date date = // a date 11/5/2008 with time 4:02:04
PreparedStatement ps = conn.prepareStatement("insert into myfile
(cmdate, cmtime) values(?, ?)");
ps.setDate(1, new java.sql.Date(date.getTime()));
ps.setTime(2, new java.sql.Time(date.getTime()));
ps.executeUpdate();

PC2

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of
TAllen@xxxxxxxxxxxx
Sent: November 5, 2008 07:16
To: Java Programming on and around the iSeries / AS400
Subject: JDBC date insert

I am having trouble with a JDBC insert of a string into date or time
columns in a database table. The same command works fine from the SQL
green screen.
The insert statement fails with the "Data type mismatch" SQL
exception.
The odd thing is that this only fails when the date or time does not
have all leading zeros.
Date of 11/14/2008 - success
Date of 11/4/2008 - error
Time of 22:00:00 - success
Time of 4:00:00 - error

The insert statement looks like this:

insert into myfile (cmdate, cmtime) values(cast('11/5/2008' as date),
cast('4:02:04' as time))

Thanks,
Todd







This communication and any transmitted documents are intended to be
confidential. If there is a problem with this transmission, please
contact
the sender. If the reader of this message is not the intended recipient,
or
the employee or agent responsible to deliver it to the intended
recipient,
you are hereby notified that any dissemination, distribution or copying
of
this communication is strictly prohibited.

--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.


--
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.





This communication and any transmitted documents are intended to be confidential. If there is a problem with this transmission, please contact the sender. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.