Thread: bug in PreparedStatement of JDBC in 7.2b4
I found a bug in PreparedStatement#setTimestamp() of JDBC included in PostgreSQL7.2beta4. An attached patch corrects this bug. (1) ".01" sec becomes ".10" sec $ create table test(ts timestamp); String sql = "insert into test values(?)"; PreparedStatement pst = db.prepareStatement(sql); pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.01")); pst.executeUpdate(); $ select * from test; $ 2002-01-10 19:30:59.10+09 Though I inserted ".01" second, ".10" second has been inserted. There is this bug in 7.2beta4 and 7.1.3. (2) ".876543210" sec becomes ".87" sec pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.876543210")); pst.executeUpdate(); $ select * from test; $ 2002-01-10 19:30:59.87+09 In PostgreSQL7.2, a decimal can insert only two columns, and remainder is thrown away.
Attachment
Ryouichi, Thank you for reporting this bug. I will work on getting your patch applied this weekend. thanks, --Barry Ryouichi Matsuda wrote: > I found a bug in PreparedStatement#setTimestamp() of JDBC included > in PostgreSQL7.2beta4. An attached patch corrects this bug. > > > (1) ".01" sec becomes ".10" sec > > $ create table test(ts timestamp); > > String sql = "insert into test values(?)"; > PreparedStatement pst = db.prepareStatement(sql); > pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.01")); > pst.executeUpdate(); > > $ select * from test; > $ 2002-01-10 19:30:59.10+09 > > Though I inserted ".01" second, ".10" second has been inserted. > There is this bug in 7.2beta4 and 7.1.3. > > > (2) ".876543210" sec becomes ".87" sec > > pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.876543210")); > pst.executeUpdate(); > > $ select * from test; > $ 2002-01-10 19:30:59.87+09 > > In PostgreSQL7.2, a decimal can insert only two columns, and remainder > is thrown away. > > > ------------------------------------------------------------------------ > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >
Barry Lind wrote: > Thank you for reporting this bug. I will work on getting your patch > applied this weekend. I attach a patch for JDBC1 of this bug. Because there was not StringBuffer#replace() in JDK1.1, I changed it. I turned the same modification into a patch for JDBC2. > Ryouichi Matsuda wrote: > > > I found a bug in PreparedStatement#setTimestamp() of JDBC included > > in PostgreSQL7.2beta4. An attached patch corrects this bug. > > > > > > (1) ".01" sec becomes ".10" sec > > > > $ create table test(ts timestamp); > > > > String sql = "insert into test values(?)"; > > PreparedStatement pst = db.prepareStatement(sql); > > pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.01")); > > pst.executeUpdate(); > > > > $ select * from test; > > $ 2002-01-10 19:30:59.10+09 > > > > Though I inserted ".01" second, ".10" second has been inserted. > > There is this bug in 7.2beta4 and 7.1.3. > > > > > > (2) ".876543210" sec becomes ".87" sec > > > > pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.876543210")); > > pst.executeUpdate(); > > > > $ select * from test; > > $ 2002-01-10 19:30:59.87+09 > > > > In PostgreSQL7.2, a decimal can insert only two columns, and remainder > > is thrown away.
Attachment
I had just commited your last patch before seeing this new patch. However, I noticed the same problem as you did and fixed it myself in the fix I just committed (although I did the padding in a slightly different way than you do here). This fix should be in 7.2RC1 (but won't be in 7.2b5). It is also available in the latest build on jdbc.postgresql.org. thanks, --Barry Ryouichi Matsuda wrote: > Barry Lind wrote: > >>Thank you for reporting this bug. I will work on getting your patch >>applied this weekend. >> > > I attach a patch for JDBC1 of this bug. > Because there was not StringBuffer#replace() in JDK1.1, I changed it. > I turned the same modification into a patch for JDBC2. > > > >>Ryouichi Matsuda wrote: >> >> >>>I found a bug in PreparedStatement#setTimestamp() of JDBC included >>>in PostgreSQL7.2beta4. An attached patch corrects this bug. >>> >>> >>>(1) ".01" sec becomes ".10" sec >>> >>> $ create table test(ts timestamp); >>> >>> String sql = "insert into test values(?)"; >>> PreparedStatement pst = db.prepareStatement(sql); >>> pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.01")); >>> pst.executeUpdate(); >>> >>> $ select * from test; >>> $ 2002-01-10 19:30:59.10+09 >>> >>>Though I inserted ".01" second, ".10" second has been inserted. >>>There is this bug in 7.2beta4 and 7.1.3. >>> >>> >>>(2) ".876543210" sec becomes ".87" sec >>> >>> pst.setTimestamp(1, Timestamp.valueOf("2002-01-10 19:30:59.876543210")); >>> pst.executeUpdate(); >>> >>> $ select * from test; >>> $ 2002-01-10 19:30:59.87+09 >>> >>>In PostgreSQL7.2, a decimal can insert only two columns, and remainder >>>is thrown away. >>>