org.sape.sqlutils
Class PreparedStatementHelper

java.lang.Object
  extended byorg.sape.sqlutils.PreparedStatementHelper

public class PreparedStatementHelper
extends Object

A helper class to bind values to a PreparedStatement. If the value is null, setNull() with appropriate parameters is called. The following types of values are supported: boolean, Boolean int, Integer long, Long double, Double BigDecimal String Date (to java.sql.Date and java.sql.Timestamp)


Constructor Summary
PreparedStatementHelper()
           
 
Method Summary
static void bind(PreparedStatement ps, int position, BigDecimal value)
          Binds a BigDecimal to a PreparedStatement.
static void bind(PreparedStatement ps, int position, boolean value)
          Binds a boolean to a PreparedStatement.
static void bind(PreparedStatement ps, int position, Boolean value)
          Binds a Boolean to a PreparedStatement.
static void bind(PreparedStatement ps, int position, double value)
          Binds a double to a PreparedStatement.
static void bind(PreparedStatement ps, int position, Double value)
          Binds a Double to a PreparedStatement.
static void bind(PreparedStatement ps, int position, int value)
          Binds a int to a PreparedStatement.
static void bind(PreparedStatement ps, int position, Integer value)
          Binds an Integer to a PreparedStatement.
static void bind(PreparedStatement ps, int position, long value)
          Binds a long to a PreparedStatement.
static void bind(PreparedStatement ps, int position, Long value)
          Binds a Long to a PreparedStatement.
static void bind(PreparedStatement ps, int position, String value)
          Binds a String to a PreparedStatement.
static void bindDate(PreparedStatement ps, int position, Date value)
          Converts a java.util.Date to a java.sql.Date and binds it to a PreparedStatement.
static void bindDate(PreparedStatement ps, int position, Date value, Calendar cal)
          Converts a java.util.Date to a java.sql.Date and binds it to a PreparedStatement.
static void bindTimestamp(PreparedStatement ps, int position, Date value)
          Converts a java.util.Date to a java.sql.Timestamp and binds it to a PreparedStatement.
static void bindTimestamp(PreparedStatement ps, int position, Date value, Calendar cal)
          Converts a java.util.Date to a java.sql.Timestamp and binds it to a PreparedStatement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreparedStatementHelper

public PreparedStatementHelper()
Method Detail

bind

public static void bind(PreparedStatement ps,
                        int position,
                        boolean value)
                 throws SQLException
Binds a boolean to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException

bind

public static void bind(PreparedStatement ps,
                        int position,
                        Boolean value)
                 throws SQLException
Binds a Boolean to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        int value)
                 throws SQLException
Binds a int to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        Integer value)
                 throws SQLException
Binds an Integer to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        long value)
                 throws SQLException
Binds a long to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        Long value)
                 throws SQLException
Binds a Long to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        double value)
                 throws SQLException
Binds a double to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        Double value)
                 throws SQLException
Binds a Double to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        BigDecimal value)
                 throws SQLException
Binds a BigDecimal to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bind

public static void bind(PreparedStatement ps,
                        int position,
                        String value)
                 throws SQLException
Binds a String to a PreparedStatement.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException - if a error occurs while binding.

bindDate

public static void bindDate(PreparedStatement ps,
                            int position,
                            Date value)
                     throws SQLException
Converts a java.util.Date to a java.sql.Date and binds it to a PreparedStatement. The database driver uses the default timezone of the JVM to store the java,sql.Date.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException

bindDate

public static void bindDate(PreparedStatement ps,
                            int position,
                            Date value,
                            Calendar cal)
                     throws SQLException
Converts a java.util.Date to a java.sql.Date and binds it to a PreparedStatement. The database driver uses the supplied Calendar's timezone to store the java,sql.Date. Note: The Oracle driver ignores the Calendar parameter! So the only way to store dates in a specific timezone is to set the JVM to that timezone.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
cal - the calendar object used to determine the timezone
Throws:
SQLException

bindTimestamp

public static void bindTimestamp(PreparedStatement ps,
                                 int position,
                                 Date value)
                          throws SQLException
Converts a java.util.Date to a java.sql.Timestamp and binds it to a PreparedStatement. The database driver uses the default timezone of the JVM to store the java.sql.Timestamp.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
Throws:
SQLException

bindTimestamp

public static void bindTimestamp(PreparedStatement ps,
                                 int position,
                                 Date value,
                                 Calendar cal)
                          throws SQLException
Converts a java.util.Date to a java.sql.Timestamp and binds it to a PreparedStatement. The database driver uses the supplied Calendar's timezone to store the java,sql.Timestamp. Note: The Oracle driver ignores the Calendar parameter! So the only way to store dates in a specific timezone is to set the JVM to that timezone.

Parameters:
ps - the PreparedStatement to be bound
position - the location to which the value is to be bound
value - the value to be bound
cal - the calendar object used to determine the timezone
Throws:
SQLException


Copyright 2003 Sapient Corporation. All Rights Reserved.