Java SQL Time setTime(PreparedStatement statement, int index, Date value)

Here you can find the source of setTime(PreparedStatement statement, int index, Date value)

Description

Sets a SQL parameter of type time using a prepared SQL statement, an index and a value.

License

Open Source License

Parameter

Parameter Description
statement - Prepared SQL statement.
index - Parameter index.
value - Parameter value.

Declaration

public static void setTime(PreparedStatement statement, int index, Date value) throws SQLException 

Method Source Code

//package com.java2s;
/*/*from   www. j a  v a 2  s  .com*/
 * Copyright (C) 2015 Bryan W. Snipes
 * 
 * This file is part of the JDistil web application framework.
 * 
 * JDistil is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * JDistil is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with JDistil.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.sql.Types;

import java.util.Date;

public class Main {
    /**
      Time type constant.
    */
    public static final int TIME = 3;

    /**
      Sets a SQL parameter of type time using a prepared SQL statement, an index
      and a value.
      @param statement - Prepared SQL statement.
      @param index - Parameter index.
      @param value - Parameter value.
    */
    public static void setTime(PreparedStatement statement, int index, Date value) throws SQLException {

        if (statement != null) {

            // Set parameter
            if (value == null) {
                statement.setNull(index, Types.TIME);
            } else {
                statement.setTime(index, new java.sql.Time(value.getTime()));
            }
        }
    }

    /**
      Returns a time value using a given SQL result set and column name.
      @param resultSet - Result set.
      @param columnName - Column name.
      @return Time - Column value.
    */
    public static Date getTime(ResultSet resultSet, String columnName) throws SQLException {

        // Initialize return value
        Date value = null;

        if (resultSet != null && columnName != null) {
            value = resultSet.getTime(columnName);
        }

        return value;
    }
}

Related

  1. roundDatetimeValue(Object value)
  2. roundSmallDateTimeValue(Object value)
  3. saveGameScores(String gameName, String player1, String player2, String player3, String player4, short score1, short score2, short score3, short score4, java.util.Date startTime)
  4. serialize(LocalDateTime date)
  5. serializeSqlTime(Time time)
  6. sqlDateTimeAdd(java.util.Date date, long milliseconds)
  7. sqlTime()
  8. str2dateTime(String handedate)
  9. StrToDateTime(String val)