Hi,

when I execute PreparedStatement.setTimestamp(1, timestamp, null); I get 
the following Exception:

org.h2.jdbc.JdbcSQLException: Unerlaubter Wert "null" für Parameter 
"calendar"
*Invalid value "null" for parameter "calendar" [90008-193]*
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.getInvalidValueException(DbException.java:228)
at org.h2.util.DateTimeUtils.convertTimestamp(DateTimeUtils.java:285)
at 
org.h2.jdbc.JdbcPreparedStatement.setTimestamp(JdbcPreparedStatement.java:718)
at 
org.apache.commons.dbcp2.DelegatingPreparedStatement.setTimestamp(DelegatingPreparedStatement.java:243)
at 
org.apache.commons.dbcp2.DelegatingPreparedStatement.setTimestamp(DelegatingPreparedStatement.java:243)
at 
org.apache.commons.dbcp2.DelegatingPreparedStatement.setTimestamp(DelegatingPreparedStatement.java:243)

I think the Exception should not be thrown according to JavaDoc of "
setTimestamp 
<https://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html#setTimestamp-int-java.sql.Timestamp-java.util.Calendar->
":

Sets the designated parameter to the given java.sql.Timestamp value, using 
the given Calendar object. The driver uses the Calendar object to construct 
an SQL TIMESTAMP value, which the driver then sends to the database. With a 
Calendar object, the driver can calculate the timestamp taking into account 
a custom timezone. *If no **Calendar** object is specified, the driver uses 
the default timezone*, which is that of the virtual machine running the 
application.


So the code should be:

/**
 * Convert the timestamp using the specified calendar.
 *
 * @param x the time
 * @param calendar the calendar
 * @return the timestamp
 */
public static ValueTimestamp convertTimestamp(Timestamp x,
        Calendar calendar) {

    Calendar cal;
    if (calendar == null) {
        //throw DbException.getInvalidValueException("calendar", null);

        *cal = Calendar.getInstance();*
    } else {
       cal = (Calendar) calendar.clone();

    }
    cal.setTimeInMillis(x.getTime());
    long dateValue = dateValueFromCalendar(cal);
    long nanos = nanosFromCalendar(cal);
    nanos += x.getNanos() % 1000000;
    return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos);

} 

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to