Bad value for type date

Поиск
Список
Период
Сортировка
От Prasanth
Тема Bad value for type date
Дата
Msg-id 4306322D.7090505@nqadmin.com
обсуждение исходный текст
Ответы Re: Bad value for type date  (Oliver Jowett <oliver@opencloud.com>)
Re: Bad value for type date  (Oliver Jowett <oliver@opencloud.com>)
Список pgsql-jdbc
Hi,

Below is a small program to test the JDBC date issue I have having.

I am able to set the date "2/1/10000". But it fails to retrieve it.

If it is invalid date then it should not even update the database right?


String sql = "SELECT * FROM table where = 9159;";
JdbcRowSetImpl rs = new JdbcRowSetImpl(connection);
rs.setCommand(sql);
rs.execute();
rs.next();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, 1);
calendar.set(Calendar.DATE, 1);
calendar.set(Calendar.YEAR, 10000);
Date date = new Date(calendar.getTimeInMillis());
System.out.println(date);
rs.updateDate("end_date", date);
rs.updateRow();
System.out.println("Date: " + rs.getDate("end_date") + "  " +
rs.getString("plan_id") +"  "+  rs.getDate("start_date"));

This causes

org.postgresql.util.PSQLException: Bad value for type date :
    at org.postgresql.jdbc2.TimestampUtils.loadCalendar(TimestampUtils.java:155)
    at org.postgresql.jdbc2.TimestampUtils.toDate(TimestampUtils.java:245)
    at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getDate(AbstractJdbc2ResultSet.java:2075)
    at com.sun.rowset.JdbcRowSetImpl.getDate(JdbcRowSetImpl.java:1087)
    at com.sun.rowset.JdbcRowSetImpl.getDate(JdbcRowSetImpl.java:1403)
    at PostgresDate.main(PostgresDate.java:30)
Caused by: java.lang.NumberFormatException
    at org.postgresql.jdbc2.TimestampUtils.number(TimestampUtils.java:407)
    at org.postgresql.jdbc2.TimestampUtils.loadCalendar(TimestampUtils.java:47)
    ... 5 more

When I query the database using psql
Below is what is in the database
| 2000-01-01 | 10000-02-01 |    9159 |

So it did update the database.

After running this I ran the following program.

String sql = "SELECT * FROM accounting_periods where plan_id = 9159;";
JdbcRowSetImpl rs = new JdbcRowSetImpl(connection);
rs.setCommand(sql);
rs.execute();
rs.next();
System.out.println("Date: " + rs.getDate("end_date") + "  " + rs.getString("id")
+"  "+  rs.getDate("start_date"));

Output:
Date:


Thanks,
-Prasanth.

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: COPY support survey
Следующее
От: Oliver Jowett
Дата:
Сообщение: Re: Bad value for type date