diff options
| author | Aaron M. Renn <arenn@urbanophile.com> | 1999-01-19 02:17:26 +0000 |
|---|---|---|
| committer | Aaron M. Renn <arenn@urbanophile.com> | 1999-01-19 02:17:26 +0000 |
| commit | 03c85396b198e22f18cd1881f5d86b7d7b5fa14f (patch) | |
| tree | cb04dc3b04c311b24fdbc4a2ba2417f402f84ac0 /java/sql | |
| parent | ea6916243746fc632554f29840d55538f1171153 (diff) | |
| download | classpath-03c85396b198e22f18cd1881f5d86b7d7b5fa14f.tar.gz | |
Initial Checkin
Diffstat (limited to 'java/sql')
| -rw-r--r-- | java/sql/CallableStatement.java | 448 | ||||
| -rw-r--r-- | java/sql/Date.java | 127 | ||||
| -rw-r--r-- | java/sql/PreparedStatement.java | 472 | ||||
| -rw-r--r-- | java/sql/Statement.java | 407 | ||||
| -rw-r--r-- | java/sql/Time.java | 131 | ||||
| -rw-r--r-- | java/sql/Timestamp.java | 279 |
6 files changed, 1864 insertions, 0 deletions
diff --git a/java/sql/CallableStatement.java b/java/sql/CallableStatement.java new file mode 100644 index 000000000..3a319e737 --- /dev/null +++ b/java/sql/CallableStatement.java @@ -0,0 +1,448 @@ +/************************************************************************* +/* CallableStatement.java -- A statement for calling stored procedures. +/* +/* Copyright (c) 1999 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This library is free software; you can redistribute it and/or modify +/* it under the terms of the GNU Library General Public License as published +/* by the Free Software Foundation, either version 2 of the License, or +/* (at your option) any later verion. +/* +/* This library 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 Library General Public License for more details. +/* +/* You should have received a copy of the GNU Library General Public License +/* along with this library; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +package java.sql; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.Map; + +/** + * This interface provides a mechanism for calling stored procedures. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public abstract interface CallableStatement +{ + +/*************************************************************************/ + +/** + * This method tests whether the value of the last parameter that was fetched + * was actually a SQL NULL value. + * + * @return <code>true</code> if the last parameter fetched was a NULL, + * <code>false</code> otherwise. + * + * @exception SQLException If an error occurs. + */ +public abstract boolean +wasNull() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>String</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>String</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract String +getString(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>Object</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as an <code>Object</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract Object +getObject(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>Object</code>. + * + * @param index The index of the parameter to return. + * @param map The mapping to use for conversion from SQL to Java types. + * + * @return The parameter value as an <code>Object</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract Object +getObject(int index, Map map) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>boolean</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>boolean</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract boolean +getBoolean(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>byte</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>byte</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract byte +getByte(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>short</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>short</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract short +getShort(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>int</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>int</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract int +getInt(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>long</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>long</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract long +getLong(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>float</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>float</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract float +getFloat(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>double</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>double</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract double +getDouble(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>BigDecimal</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>BigDecimal</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract BigDecimal +getBigDecimal(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>BigDecimal</code>. + * + * @param index The index of the parameter to return. + * @param scale The number of digits to the right of the decimal to return. + * + * @return The parameter value as a <code>BigDecimal</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract BigDecimal +getBigDecimal(int index, int scale) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * byte array. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a byte array + * + * @exception SQLException If an error occurs. + */ +public abstract byte[] +getBytes(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>java.sql.Date</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>java.sql.Date</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract java.sql.Date +getDate(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>java.sql.Date</code>. + * + * @param index The index of the parameter to return. + * @param calendar The <code>Calendar</code> to use for timezone and locale. + * + * @return The parameter value as a <code>java.sql.Date</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract java.sql.Date +getDate(int index, Calendar calendar) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>java.sql.Time</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>java.sql.Time</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract java.sql.Time +getTime(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>java.sql.Time</code>. + * + * @param index The index of the parameter to return. + * @param calendar The <code>Calendar</code> to use for timezone and locale. + * + * @return The parameter value as a <code>java.sql.Time</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract java.sql.Time +getTime(int index, Calendar calendar) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>java.sql.Timestamp</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>java.sql.Timestamp</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract java.sql.Timestamp +getTimestamp(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>java.sql.Timestamp</code>. + * + * @param index The index of the parameter to return. + * @param calendar The <code>Calendar</code> to use for timezone and locale. + * + * @return The parameter value as a <code>java.sql.Timestamp</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract java.sql.Timestamp +getTimestamp(int index, Calendar calendar) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>Ref</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>Ref</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract Ref +getRef(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>Blob</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>Blob</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract Blob +getBlob(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>Clob</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>Clob</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract Clob +getClob(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the value of the specified parameter as a Java + * <code>Array</code>. + * + * @param index The index of the parameter to return. + * + * @return The parameter value as a <code>Array</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract Array +getArray(int index) throws SQLException; + +/*************************************************************************/ + +/** + * This method registers the specified parameter as an output parameter + * of the specified SQL type. + * + * @param index The index of the parameter to register as output. + * @param type The SQL type value from <code>Types</code>. + * + * @exception SQLException If an error occurs. + */ +public abstract void +registerOutParameter(int index, int type) throws SQLException; + +/*************************************************************************/ + +/** + * This method registers the specified parameter as an output parameter + * of the specified SQL type. + * + * @param index The index of the parameter to register as output. + * @param type The SQL type value from <code>Types</code>. + * @param name The user defined data type name. + * + * @exception SQLException If an error occurs. + */ +public abstract void +registerOutParameter(int index, int type, String name) throws SQLException; + +/*************************************************************************/ + +/** + * This method registers the specified parameter as an output parameter + * of the specified SQL type and scale. + * + * @param index The index of the parameter to register as output. + * @param type The SQL type value from <code>Types</code>. + * @param scale The scale of the value that will be returned. + * + * @exception SQLException If an error occurs. + */ +public abstract void +registerOutParameter(int index, int type, int scale) throws SQLException; + +} // interface CallableStatement + + diff --git a/java/sql/Date.java b/java/sql/Date.java new file mode 100644 index 000000000..eac85ae7a --- /dev/null +++ b/java/sql/Date.java @@ -0,0 +1,127 @@ +/************************************************************************* +/* Date.java -- Wrapper around java.util.Date +/* +/* Copyright (c) 1999 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This library is free software; you can redistribute it and/or modify +/* it under the terms of the GNU Library General Public License as published +/* by the Free Software Foundation, either version 2 of the License, or +/* (at your option) any later verion. +/* +/* This library 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 Library General Public License for more details. +/* +/* You should have received a copy of the GNU Library General Public License +/* along with this library; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +package java.sql; + +import java.text.SimpleDateFormat; + +/** + * This class is a wrapper around java.util.Date to allow the JDBC + * driver to identify the value as a SQL Date. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class Date extends java.util.Date +{ + +/* + * Class Variables + */ + +/** + * Used for parsing and formatting this date. + */ +private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + +/*************************************************************************/ + +/* + * Class Methods + */ + +/** + * This method returns a new instance of this class by parsing a + * date in JDBC format into a Java date. + * + * @param str The string to parse. + * + * @return The resulting <code>java.sql.Date</code> value. + */ +public static Date +valueOf(String str) +{ + try + { + java.util.Date d = (java.util.Date)sdf.parseObject(str); + return(new Date(d.getTime())); + } + catch(Exception e) + { + return(null); + } +} + +/*************************************************************************/ + +/* + * Constructors + */ + +/** + * This method initializes a new instance of this class with the + * specified year, month, and day. + * + * @param year The year of this date minue 1900. + * @param month The month of this date (0-11). + * @param day The day of this date (1-31). + * + * @deprecated + */ +public +Date(int year, int month, int day) +{ + super(year, month, day); +} + +/*************************************************************************/ + +/** + * This method initializes a new instance of this class with the + * specified time value representing the number of seconds since + * Jan 1, 1970 at 12:00 midnight GMT. + * + * @param time The time value to intialize this date to. + */ +public +Date(long date) +{ + super(date); +} + +/*************************************************************************/ + +/* + * Instance Methods + */ + +/** + * This method returns this date in JDBC format. + * + * @return This date as a string. + */ +public String +toString() +{ + return(sdf.format(this)); +} + +} // class Date + diff --git a/java/sql/PreparedStatement.java b/java/sql/PreparedStatement.java new file mode 100644 index 000000000..02cf7eda5 --- /dev/null +++ b/java/sql/PreparedStatement.java @@ -0,0 +1,472 @@ +/************************************************************************* +/* PreparedStatement.java -- Interface for pre-compiled statements. +/* +/* Copyright (c) 1999 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This library is free software; you can redistribute it and/or modify +/* it under the terms of the GNU Library General Public License as published +/* by the Free Software Foundation, either version 2 of the License, or +/* (at your option) any later verion. +/* +/* This library 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 Library General Public License for more details. +/* +/* You should have received a copy of the GNU Library General Public License +/* along with this library; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +package java.sql; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.util.Calendar; + +/** + * This interface provides a mechanism for executing pre-compiled + * statements. This provides greater efficiency when calling the same + * statement multiple times. Parameters are allowed in a statement, + * providings for maximum reusability. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public abstract interface PreparedStatement +{ + +/** + * This method populates the specified parameter with a SQL NULL value + * for the specified type. + * + * @param index The index of the parameter to set. + * @param type The SQL type identifier of the parameter from <code>Types</code> + * + * @exception SQLException If an error occurs. + */ +public abstract void +setNull(int index, int type) throws SQLException; + +/*************************************************************************/ + +/** + * This method populates the specified parameter with a SQL NULL value + * for the specified type. + * + * @param index The index of the parameter to set. + * @param type The SQL type identifier of the parameter from <code>Types</code> + * @param name The name of the data type, for user defined types. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setNull(int index, int type, String name) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>boolean</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setBoolean(int index, boolean value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>byte</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setByte(int index, byte value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>short</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setShort(int index, short value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>int</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setInt(int index, int value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>long</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setLong(int index, long value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>float</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setFloat(int index, float value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>double</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setDouble(int index, double value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>String</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setString(int index, String value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>byte</code> array value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setBytes(int index, byte[] value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>java.sql.Date</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setDate(int index, java.sql.Date value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>java.sql.Date</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * @param calendar The <code>Calendar</code> to use for timezone and locale. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setDate(int index, java.sql.Date value, Calendar calendar) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>java.sql.Time</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setTime(int index, java.sql.Time value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>java.sql.Time</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * @param calendar The <code>Calendar</code> to use for timezone and locale. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setTime(int index, java.sql.Time value, Calendar calendar) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>java.sql.Timestamp</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setTimestamp(int index, java.sql.Timestamp value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>java.sql.Timestamp</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * @param calendar The <code>Calendar</code> to use for timezone and locale. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setTimestamp(int index, java.sql.Timestamp value, Calendar calendar) + throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * ASCII <code>InputStream</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * @param calendar The <code>Calendar</code> to use for timezone and locale. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setAsciiStream(int index, InputStream value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * Unicode UTF-8 <code>InputStream</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setUnicodeStream(int index, InputStream value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * binary <code>InputStream</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setBinaryStream(int index, InputStream value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * character <code>Reader</code> value. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setCharacterStream(int index, Reader value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>Ref</code> value. The default object type to SQL type mapping + * will be used. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setRef(int index, Ref value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>Blob</code> value. The default object type to SQL type mapping + * will be used. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setBlob(int index, Blob value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>Clob</code> value. The default object type to SQL type mapping + * will be used. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setClob(int index, Clob value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>Array</code> value. The default object type to SQL type mapping + * will be used. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setArray(int index, Array value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>Object</code> value. The default object type to SQL type mapping + * will be used. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setObject(int index, Object value) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>Object</code> value. The specified SQL object type will be used. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * @param type The SQL type to use for the parameter, from <code>Types</code> + * + * @exception SQLException If an error occurs. + * + * @see Types + */ +public abstract void +setObject(int index, Object value, int type) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the specified parameter from the given Java + * <code>Object</code> value. The specified SQL object type will be used. + * + * @param index The index of the parameter value to set. + * @param value The value of the parameter. + * @param type The SQL type to use for the parameter, from <code>Types</code> + * @param scale The scale of the value, for numeric values only. + * + * @exception SQLException If an error occurs. + * + * @see Types + */ +public abstract void +setObject(int index, Object value, int type, int scale) throws SQLException; + +/*************************************************************************/ + +/** + * This method clears all of the input parameter that have been + * set on this statement. + * + * @exception SQLException If an error occurs. + */ +public abstract void +clearParameters() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns meta data for the result set from this statement. + * + * @return Meta data for the result set from this statement. + * + * @exception SQLException If an error occurs. + */ +public abstract ResultSetMetaData +getMetaData() throws SQLException; + +} // interface PreparedStatement + diff --git a/java/sql/Statement.java b/java/sql/Statement.java new file mode 100644 index 000000000..f30b52fdf --- /dev/null +++ b/java/sql/Statement.java @@ -0,0 +1,407 @@ +/************************************************************************* +/* Statement.java -- Interface for executing SQL statements. +/* +/* Copyright (c) 1999 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This library is free software; you can redistribute it and/or modify +/* it under the terms of the GNU Library General Public License as published +/* by the Free Software Foundation, either version 2 of the License, or +/* (at your option) any later verion. +/* +/* This library 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 Library General Public License for more details. +/* +/* You should have received a copy of the GNU Library General Public License +/* along with this library; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +package java.sql; + +/** + * This interface provides a mechanism for executing SQL statements. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public abstract interface Statement +{ + +/** + * This method executes the specified SQL SELECT statement and returns a + * (possibly empty) <code>ResultSet</code> with the results of the query. + * + * @param sql The SQL statement to execute. + * + * @return The result set of the SQL statement. + * + * @exception SQLException If an error occurs. + */ +public abstract ResultSet +executeQuery(String sql) throws SQLException; + +/*************************************************************************/ + +/** + * This method executes the specified SQL INSERT, UPDATE, or DELETE statement + * and returns the number of rows affected, which may be 0. + * + * @param sql The SQL statement to execute. + * + * @return The number of rows affected by the SQL statement. + * + * @exception SQLException If an error occurs. + */ +public abstract int +executeUpdate(String sql) throws SQLException; + +/*************************************************************************/ + +/** + * This method closes the statement and frees any associated resources. + * + * @exception SQLException If an error occurs. + */ +public abstract void +close() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the maximum length of any column value in bytes. + * + * @return The maximum length of any column value in bytes. + * + * @exception SQLException If an error occurs. + */ +public abstract int +getMaxFieldSize() throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the limit for the maximum length of any column in bytes. + * + * @param maxsize The new maximum length of any column in bytes. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setMaxFieldSize(int maxsize) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the maximum possible number of rows in a result set. + * + * @return The maximum possible number of rows in a result set. + * + * @exception SQLException If an error occurs. + */ +public abstract int +getMaxRows() throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the maximum number of rows that can be present in a + * result set. + * + * @param maxrows The maximum possible number of rows in a result set. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setMaxRows(int maxrows) throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the local escape processing mode on or off. The + * default value is on. + * + * @param escape <code>true</code> to enable local escape processing, + * <code>false</code> to disable it. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setEscapeProcessing(boolean esacpe) throws SQLException; + +/*************************************************************************/ + +/** + * The method returns the number of seconds a statement may be in process + * before timing out. A value of 0 means there is no timeout. + * + * @return The SQL statement timeout in seconds. + * + * @exception SQLException If an error occurs. + */ +public abstract int +getQueryTimeout() throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the number of seconds a statement may be in process + * before timing out. A value of 0 means there is no timeout. + * + * @param timeout The new SQL statement timeout value. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setQueryTimeout(int timeout) throws SQLException; + +/*************************************************************************/ + +/** + * This method cancels an outstanding statement, if the database supports + * that operation. + * + * @exception SQLException If an error occurs. + */ +public abstract void +cancel() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the first SQL warning attached to this statement. + * Subsequent warnings will be chained to this one. + * + * @return The first SQL warning for this statement. + * + * @exception SQLException If an error occurs. + */ +public abstract SQLWarning +getWarnings() throws SQLException; + +/*************************************************************************/ + +/** + * This method clears any SQL warnings that have been attached to this + * statement. + * + * @exception SQLException If an error occurs. + */ +public abstract void +clearWarnings() throws SQLException; + +/*************************************************************************/ + +/** + * This method sets the cursor name that will be used by the result set. + * + * @param name The cursor name to use for this statement. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setCursorName(String name) throws SQLException; + +/*************************************************************************/ + +/** + * This method executes an arbitrary SQL statement of any time. The + * methods <code>getResultSet</code>, <code>getMoreResults</code> and + * <code>getUpdateCount</code> retrieve the results. + * + * @return <code>true</code> if a result set was returned, <code>false</code> + * if an update count was returned. + * + * @exception SQLException If an error occurs. + */ +public abstract boolean +execute(String sql) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the result set of the SQL statement that was + * executed. This should be called only once per result set returned. + * + * @return The result set of the query, or <code>null</code> if there was + * no result set (for example, if the statement was an UPDATE). + * + * @exception SQLException If an error occurs. + * + * @see execute + */ +public abstract ResultSet +getResultSet() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the update count of the SQL statement that was + * executed. This should be called only once per executed SQL statement. + * + * @return The update count of the query, or -1 if there was no update + * count (for example, if the statement was a SELECT). + * + * @exception SQLException If an error occurs. + * + * @see execute + */ +public abstract int +getUpdateCount() throws SQLException; + +/*************************************************************************/ + +/** + * This method advances the result set pointer to the next result set, + * which can then be retrieved using <code>getResultSet</code> + * + * @return <code>true</code> if there is another result set, + * <code>false</code> otherwise (for example, the next result is an + * update count). + * + * @exception SQLException If an error occurs. + * + * @see execute + */ +public abstract boolean +getMoreResults() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the current direction that the driver thinks the + * result set will be accessed int. + * + * @return The direction the result set will be accessed in (????) + * + * @exception SQLException If an error occurs. + */ +public abstract int +getFetchDirection() throws SQLException; + +/*************************************************************************/ + +/** + * This method informs the driver which direction the result set will + * be accessed in. + * + * @param direction The direction the result set will be accessed in (?????) + * + * @exception SQLException If an error occurs. + */ +public abstract void +setFetchDirection(int direction) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the number of rows the driver believes should be + * fetched from the database at a time. + * + * @return The number of rows that will be fetched from the database at a time. + * + * @exception SQLException If an error occurs. + */ +public abstract int +getFetchSize() throws SQLException; + +/*************************************************************************/ + +/** + * This method informs the driver how many rows it should fetch from the + * database at a time. + * + * @param numrows The number of rows the driver should fetch at a time + * to populate the result set. + * + * @exception SQLException If an error occurs. + */ +public abstract void +setFetchSize(int numrows) throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the concurrency type of the result set for this + * statement. This will be one of the concurrency types defined in + * <code>ResultSet</code>. + * + * @return The concurrency type of the result set for this statement. + * + * @exception SQLException If an error occurs. + * + * @see ResultSet + */ +public abstract int +getResultSetConcurrency() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the result set type for this statement. This will + * be one of the result set types defined in <code>ResultSet</code>. + * + * @return The result set type for this statement. + * + * @exception SQLException If an error occurs. + * + * @see ResultSet + */ +public abstract int +getResultSetType() throws SQLException; + +/*************************************************************************/ + +/** + * This method adds a SQL statement to a SQL batch. A driver is not + * required to implement this method. + * + * @param sql The sql statement to add to the batch. + * + * @exception SQLException If an error occurs. + */ +public abstract void +addBatch(String sql) throws SQLException; + +/*************************************************************************/ + +/** + * This method clears out any SQL statements that have been populated in + * the current batch. A driver is not required to implement this method. + * + * @exception SQLException If an error occurs. + */ +public abstract void +clearBatch() throws SQLException; + +/*************************************************************************/ + +/** + * This method executes the SQL batch and returns an array of update + * counts - one for each SQL statement in the batch - ordered in the same + * order the statements were added to the batch. A driver is not required + * to implement this method. + * + * @return An array of update counts for this batch. + * + * @exception SQLException If an error occurs. + */ +public abstract int[] +executeBatch() throws SQLException; + +/*************************************************************************/ + +/** + * This method returns the <code>Connection</code> instance that was + * used to create this object. + * + * @return The connection used to create this object. + * + * @exception SQLException If an error occurs. + */ +public abstract Connection +getConnection() throws SQLException; + +} // interface Statement + diff --git a/java/sql/Time.java b/java/sql/Time.java new file mode 100644 index 000000000..e9a8fc9bc --- /dev/null +++ b/java/sql/Time.java @@ -0,0 +1,131 @@ +/************************************************************************* +/* Time.java -- Wrapper around java.util.Date +/* +/* Copyright (c) 1999 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This library is free software; you can redistribute it and/or modify +/* it under the terms of the GNU Library General Public License as published +/* by the Free Software Foundation, either version 2 of the License, or +/* (at your option) any later verion. +/* +/* This library 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 Library General Public License for more details. +/* +/* You should have received a copy of the GNU Library General Public License +/* along with this library; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +package java.sql; + +import java.text.SimpleDateFormat; + +/** + * This class is a wrapper around java.util.Date to allow the JDBC + * driver to identify the value as a SQL Time. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class Time extends java.util.Date +{ + +/* + * Class Variables + */ + +/** + * Used for parsing and formatting this date. + */ +private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + +/*************************************************************************/ + +/* + * Class Methods + */ + +/** + * This method returns a new instance of this class by parsing a + * date in JDBC format into a Java date. + * + * @param str The string to parse. + * + * @return The resulting <code>java.sql.Time</code> value. + */ +public static Time +valueOf(String str) +{ + try + { + java.util.Date d = (java.util.Date)sdf.parseObject(str); + return(new Time(d.getTime())); + } + catch(Exception e) + { + return(null); + } +} + +/*************************************************************************/ + +/* + * Constructors + */ + +/** + * This method initializes a new instance of this class with the + * specified year, month, and day. + * + * @param hour The hour for this Time (0-23) + * @param minute The minute for this time (0-59) + * @param second The second for this time (0-59) + * + * @deprecated + */ +public +Time(int hour, int minute, int second) +{ + super(System.currentTimeMillis()); + + setHours(hour); + setMinutes(minute); + setSeconds(second); +} + +/*************************************************************************/ + +/** + * This method initializes a new instance of this class with the + * specified time value representing the number of seconds since + * Jan 1, 1970 at 12:00 midnight GMT. + * + * @param time The time value to intialize this <code>Time</code> to. + */ +public +Time(long date) +{ + super(date); +} + +/*************************************************************************/ + +/* + * Instance Methods + */ + +/** + * This method returns this date in JDBC format. + * + * @return This date as a string. + */ +public String +toString() +{ + return(sdf.format(this)); +} + +} // class Time + diff --git a/java/sql/Timestamp.java b/java/sql/Timestamp.java new file mode 100644 index 000000000..246528228 --- /dev/null +++ b/java/sql/Timestamp.java @@ -0,0 +1,279 @@ +/************************************************************************* +/* Time.java -- Wrapper around java.util.Date +/* +/* Copyright (c) 1999 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This library is free software; you can redistribute it and/or modify +/* it under the terms of the GNU Library General Public License as published +/* by the Free Software Foundation, either version 2 of the License, or +/* (at your option) any later verion. +/* +/* This library 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 Library General Public License for more details. +/* +/* You should have received a copy of the GNU Library General Public License +/* along with this library; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +package java.sql; + +import java.text.SimpleDateFormat; + +/** + * This class is a wrapper around java.util.Date to allow the JDBC + * driver to identify the value as a SQL Timestamp. Note that this + * class also adds an additional field for nano-seconds, and so + * is not completely identical to <code>java.util.Date</code> as + * the <code>java.sql.Date</code> and <code>java.sql.Time</code> + * classes are. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class Timestamp extends java.util.Date +{ + +/* + * Class Variables + */ + +/** + * Used for parsing and formatting this date. + */ + // Millisecond will have to be close enough for now. +private static SimpleDateFormat parse_sdf = + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSS"); + +private static SimpleDateFormat format_sdf = + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + +/*************************************************************************/ + +/* + * Instance Variables + */ + +/** + * @serial The nanosecond value for this object + */ +private int nanos; + +/*************************************************************************/ + +/* + * Class Methods + */ + +/** + * This method returns a new instance of this class by parsing a + * date in JDBC format into a Java date. + * + * @param str The string to parse. + * + * @return The resulting <code>java.sql.Timestamp</code> value. + */ +public static Timestamp +valueOf(String str) +{ + try + { + Date d = (Date)parse_sdf.parseObject(str); + return(new Timestamp(d.getTime())); + } + catch(Exception e) + { + return(null); + } +} + +/*************************************************************************/ + +/* + * Constructors + */ + +/** + * This method initializes a new instance of this class with the + * specified year, month, and day. + * + * @param year The year for this Timestamp (year - 1900) + * @param month The month for this Timestamp (0-11) + * @param day The day for this Timestamp (1-31) + * @param hour The hour for this Timestamp (0-23) + * @param minute The minute for this Timestamp (0-59) + * @param second The second for this Timestamp (0-59) + * @param nanos The nanosecond value for this Timestamp (0 to 999,999,9999) + * + * @deprecated + */ +public +Timestamp(int year, int month, int day, int hour, int minute, int second, + int nanos) +{ + super(year, month, day, hour, minute, second); + + this.nanos = nanos; +} + +/*************************************************************************/ + +/** + * This method initializes a new instance of this class with the + * specified time value representing the number of seconds since + * Jan 1, 1970 at 12:00 midnight GMT. + * + * @param time The time value to intialize this <code>Time</code> to. + */ +public +Timestamp(long date) +{ + super(date); +} + +/*************************************************************************/ + +/* + * Instance Methods + */ + +/** + * This method returns this date in JDBC format. + * + * @return This date as a string. + */ +public String +toString() +{ + return(format_sdf.format(this) + "." + getNanos()); +} + +/*************************************************************************/ + +/** + * This method returns the nanosecond value for this object. + * + * @return The nanosecond value for this object. + */ +public int +getNanos() +{ + return(nanos); +} + +/*************************************************************************/ + +/** + * This method sets the nanosecond value for this object. + * + * @param nanos The nanosecond value for this object. + */ +public void +setNanos(int nanos) +{ + this.nanos = nanos; +} + +/*************************************************************************/ + +/** + * This methods tests whether this object is earlier than the specified + * object. + * + * @param ts The other <code>Timestamp</code> to test against. + * + * @return <code>true</code> if this object is earlier than the other object, + * <code>false</code> otherwise. + */ +public boolean +before(Timestamp ts) +{ + if (ts.getTime() > getTime()) + return(true); + + if (ts.getNanos() > getNanos()) + return(true); + + return(false); +} + +/*************************************************************************/ + +/** + * This methods tests whether this object is later than the specified + * object. + * + * @param ts The other <code>Timestamp</code> to test against. + * + * @return <code>true</code> if this object is later than the other object, + * <code>false</code> otherwise. + */ +public boolean +after(Timestamp ts) +{ + if (ts.getTime() < getTime()) + return(true); + + if (ts.getNanos() < getNanos()) + return(true); + + return(false); +} + +/*************************************************************************/ + +/** + * This method these the specified <code>Object</code> for equality + * against this object. This will be true if an only if the specified + * object is an instance of <code>Timestamp</code> and has the same + * time value fields. + * + * @param obj The object to test against for equality. + * + * @return <code>true</code> if the specified object is equal to this + * object, <code>false</code> otherwise. + */ +public boolean +equals(Object obj) +{ + if (obj == null) + return(false); + + if (!(obj instanceof Timestamp)) + return(false); + + return(equals((Timestamp)obj)); +} + +/*************************************************************************/ + +/** + * This method tests the specified timestamp for equality against this + * object. This will be true if and only if the specified object is + * not <code>null</code> and contains all the same time value fields + * as this object. + * + * @param ts The <code>Timestamp</code> to test against for equality. + * + * @return <code>true</code> if the specified object is equal to this + * object, <code>false</code> otherwise. + */ +public boolean +equals(Timestamp ts) +{ + if (ts == null) + return(false); + + if (ts.getTime() != getTime()) + return(false); + + if (ts.getNanos() != getNanos()) + return(false); + + return(true); +} + +} // class Timestamp + |
