Re: Corrupted varchar2 strings with ojdbc14.jar and Oracle 8.1.6

From: Mark Meytin <mark_at_meytin.com>
Date: Fri, 15 Aug 2003 13:32:14 -0400
Message-ID: <14CdnY2iY5yQhKCiRTvU2Q_at_speakeasy.net>


For someone's benefit I'm posting the solution to my problem, which was in part provided by Oracle Metalink forums. The problem itself had to do with the way Oracle handles dates, and was probably related to a bug in 9.x drivers (2199718 CORRUPTED NUMBER COL IF NEXT BIND PARAMETER IS TIMESTAMP (9.2CLIENT->9.1DB). Changing from setDate() to setTimestamp() seems to have corrected it. I made the following change in the code:

Replace:
pstmt.setDate(3, new java.sql.Date(release.getDateReleased().getTime()));

With:
pstmt.setTimestamp(3, new java.sql.Timestamp(release.getDateReleased().getTime()));

This solved the problem. It's curious that in other places in the code I didn't have the problem in a similar situation.

-M-

Mark Meytin wrote:
> Hello!
>
> I run into the following problem and the behavior is buffling to me. We
> have a web-based application that, among other things, needs to update
> some data in Oracle database. The code is very straight-forward and
> looks something like this (simplified):
>
> private static final String updateReleaseSQL =
> "UPDATE Releases SET Title=?, Num=?, DateReleased=? "
> + "WHERE Id = ?";
>
> [...]
>
> pstmt = conn.prepareStatement(updateReleaseSQL);
> pstmt.setString(1, release.getTitle());
> pstmt.setString(2, release.getNum());
> if (release.getDateReleased() == null) {
> pstmt.setNull(3, java.sql.Types.DATE);
> } else {
> pstmt.setDate(3, new
> java.sql.Date(release.getDateReleased().getTime()));
> }
> pstmt.setInt(4, release.getId());
> pstmt.executeUpdate();
> closeStatement(pstmt);
>
> The problem that I'm reliably seeing occurs when runnig the above code
> using the latest Oracle JDBC Thin drivers (9.2.0.3, ojdbc14.jar) and
> J2SDK 1.4.2 against Oracle 8 database (8.1.6.3.0). What happens is the
> value of Title (varchar2(255) gets corrupted everytime I execute the
> code - the first three characters of the Title change to garbage. It's
> always first three characters, always during the update. When I switched
> the drivers to version 8.1.7.1 downloaded from OTN the problem appears
> to have gone away. But the 8.1.7.1 drivers are not approved for use with
> JDK's 1.4.x.
>
> Any ideas what could be causing the issue, and how can I resolve it and
> go back to the latest released JDBC drivers approved for use with JDK
> 1.4? Thanks in advance!
>
> -M-
>
Received on Fri Aug 15 2003 - 19:32:14 CEST

Original text of this message