|
Oracle JDBC API Reference 11g Release 2 ("11.2.0.3.0") |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oracle.sql.Datum oracle.sql.DATE
public class DATE
DATE Class
The DATE
class provides conversions between the Oracle Date
(ldx_t) data type and Java classes java.sql.Date
,
java.sql.Time
, java.sql.Timestamp
The internal data for this object is stored as a seven byte array in the super class' storage area. The bytes are arranged as follows:
Byte Represents 0 Century (19 for 1990) 1 Decade (90 for 1990) 2 Month 3 Day 4 Hour 5 Minute 6 Seconds
Static methods are used for conversions.
Field Summary | |
---|---|
static int |
BDA
Bad day: above range |
static int |
BDAL
Bad day: below range |
static int |
BDT
Bad date format |
static int |
BHR
Bad hour: above range |
static int |
BHRL
Bad hour: below range |
static int |
BMN
Bad minute: above range |
static int |
BMNL
Bad minute: below range |
static int |
BMO
Bad month: above range |
static int |
BMOL
Bad month: below range |
static int |
BSC
Bad second: above range |
static int |
BSCL
Bad second: below range |
static java.lang.String |
BUILD_DATE
|
static int |
BYR
Bad year: above range |
static int |
BYRL
Bad year: below range |
static int |
HRZER0
Zero valued hour |
static int |
MIZERO
Zero valued minute |
static int |
MSD
Day is one of those "missing" from the year 1582 |
static int |
SEZERO
Zero valued second |
static boolean |
TRACE
|
static int |
YR0
Year zero does not exist |
Constructor Summary | |
---|---|
DATE()
Constructs a DATE object initialized to 1/1/1970. |
|
DATE(byte[] date)
Create a DATE object represented by the given Oracle Date. |
|
DATE(java.sql.Date date)
Create a DATE object given a Java Date object. |
|
DATE(java.sql.Date date,
java.util.Calendar cal)
Create a DATE object given a Java Date object and a Calendar |
|
DATE(java.lang.Object obj)
Constructs a DATE object initialized to the value specified by the object |
|
DATE(java.lang.Object obj,
java.util.Calendar cal)
Constructs a DATE object initialized to the value specified by the object and a Calendar |
|
DATE(java.lang.String str)
Create a DATE object given a Java String object. |
|
DATE(java.lang.String str,
boolean lenient)
Create a DATE object given a Java String object. |
|
DATE(java.lang.String str,
java.util.Calendar cal)
Create a DATE object given a Java String object and a Calendar |
|
DATE(java.sql.Time time)
Create a DATE object given a Java Time object. |
|
DATE(java.sql.Time time,
java.util.Calendar cal)
Create a DATE object given a Java Time object and a Calendar |
|
DATE(java.sql.Timestamp timestamp)
Create a DATE object given a Java Timestamp object |
|
DATE(java.sql.Timestamp timestamp,
java.util.Calendar cal)
Create a DATE object given a Java Timestamp object and a Calendar |
Method Summary | |
---|---|
DATE |
addJulianDays(int julianDay,
int julianSec)
Add Julian days to a date. |
DATE |
addMonths(int months)
Add months to a date. |
static int |
checkValidity(byte[] date)
Checks the DATE passed in. |
int |
compareTo(DATE date)
Returns -1 if DATE is less than date, 0 if DATE and date are equal (==), 1 if DATE is greater than date. |
java.sql.Date |
dateValue()
Calls toDate to convert internal Oracle Date to a Java Date. |
java.sql.Date |
dateValue(java.util.Calendar cal)
Calls toDate to convert internal Oracle Date and Calendar to a Java Date. |
void |
diffInJulianDays(DATE date,
int[] julianDay,
int[] julianSec)
Calculates the difference between two dates in Julian days. |
NUMBER |
diffInMonths(DATE date)
Calculates the difference between two dates in months. |
static DATE |
fromJulianDays(int julianDay,
int julianSec)
Convert given julian days and seconds to an Oracle Date. |
static DATE |
fromText(java.lang.String datestr,
java.lang.String fmt,
java.lang.String lang)
Convert a string to a DATE object. |
static DATE |
getCurrentDate()
Gets current date and time |
boolean |
isConvertibleTo(java.lang.Class cls)
Determines if the object can be converted to a particular class |
DATE |
lastDayOfMonth()
returns a DATE object intialized to the last day of the month . |
java.lang.Object |
makeJdbcArray(int arraySize)
Returns a JDBC array representation of the datum |
static void |
numberToJulianDays(NUMBER num,
int[] julianDay,
int[] julianSec)
Converts an Oracle Number to julian days and seconds |
static byte[] |
parseFormat(java.lang.String fmt,
java.lang.String lang)
Converts the fmt string into tokens for use by toText(). |
DATE |
round(java.lang.String prec)
returns a DATE object with date rounded to specified precision |
DATE |
setDayOfWeek(int day)
returns a DATE object initialized to date advanced to the week of the day specified. |
java.lang.String |
stringValue()
Calls toString to convert internal Oracle Date to a Java String. |
java.sql.Timestamp |
timestampValue()
Calls toTimestamp to convert internal Oracle Date to a Java Timestamp. |
java.sql.Timestamp |
timestampValue(java.util.Calendar cal)
Calls toTimestamp to convert internal Oracle Date and Calendar to a Java Timestamp. |
java.sql.Time |
timeValue()
Calls toTime to convert internal Oracle Date to a Java Time. |
java.sql.Time |
timeValue(java.util.Calendar cal)
Calls toTime to convert internal Oracle Date and Calendar to a Java Time. |
byte[] |
toBytes()
|
static byte[] |
toBytes(java.sql.Date date)
Convert Java Date to Oracle Date. |
static byte[] |
toBytes(java.sql.Date date,
java.util.Calendar cal)
Convert Java Date and Calendar to Oracle Date. |
static byte[] |
toBytes(java.lang.String str)
Convert Java String to Oracle Date. |
static byte[] |
toBytes(java.lang.String str,
java.util.Calendar cal)
Convert Java String to Oracle Date. |
static byte[] |
toBytes(java.sql.Time time)
Convert Java Time to Oracle Date. |
static byte[] |
toBytes(java.sql.Time time,
java.util.Calendar cal)
Convert Java Time and Calendar to Oracle Date. |
static byte[] |
toBytes(java.sql.Timestamp timestamp)
Convert Java Timestamp to Oracle Date. |
static byte[] |
toBytes(java.sql.Timestamp timestamp,
java.util.Calendar cal)
Convert Java Timestamp and Calendar to Oracle Date. |
static java.sql.Date |
toDate(byte[] date)
Convert Oracle Date to Java Date. |
static java.sql.Date |
toDate(byte[] date,
java.util.Calendar cal)
Convert Oracle Date and Calendar to Java Date. |
java.lang.Object |
toJdbc()
Returns the JDBC representation of the datum object |
void |
toJulianDays(int[] julianDay,
int[] julianSec)
Convert to julian days and seconds from the given date. |
NUMBER |
toNumber()
Converts date to an Oracle Number. |
java.lang.String |
toString()
|
static java.lang.String |
toString(byte[] bytes)
Converts a date to a string |
java.lang.String |
toText(byte[] pfmt,
java.lang.String lang)
Convert date to text as specified by fmt. |
java.lang.String |
toText(java.lang.String fmt,
java.lang.String lang)
Convert date to text as specified by fmt. |
static java.sql.Time |
toTime(byte[] date)
Convert Oracle Date to Java Time. |
static java.sql.Time |
toTime(byte[] date,
java.util.Calendar cal)
Convert Oracle Date and Calendar to Java Time. |
static java.sql.Timestamp |
toTimestamp(byte[] date)
Convert Oracle Date to Java Timestamp. |
static java.sql.Timestamp |
toTimestamp(byte[] date,
java.util.Calendar cal)
Convert Oracle Date and Calendar to Java Timestamp. |
DATE |
truncate(java.lang.String prec)
returns a DATE object with date truncated to specified precision |
Methods inherited from class oracle.sql.Datum |
---|
asciiStreamValue, bigDecimalValue, binaryStreamValue, booleanValue, byteValue, characterStreamValue, doubleValue, equals, floatValue, getBytes, getLength, getStream, intValue, longValue, setBytes, setShareBytes, shareBytes, stringValue |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int BDA
public static final int BDAL
public static final int BMO
public static final int BMOL
public static final int BYR
public static final int BYRL
public static final int BHR
public static final int BHRL
public static final int BMN
public static final int BMNL
public static final int BSC
public static final int BSCL
public static final int MSD
public static final int YR0
public static final int BDT
public static final int HRZER0
public static final int MIZERO
public static final int SEZERO
public static final java.lang.String BUILD_DATE
public static final boolean TRACE
Constructor Detail |
---|
public DATE()
public DATE(byte[] date)
date
- Oracle Datepublic DATE(java.sql.Date date)
date
- Java Date objectpublic DATE(java.sql.Time time)
time
- Java Time objectpublic DATE(java.sql.Timestamp timestamp)
timestamp
- Java Timestamp objectpublic DATE(java.sql.Date date, java.util.Calendar cal)
date
- Java Date objectcal
- Java Calendar object which encapsulates the timezone
information of datepublic DATE(java.sql.Time time, java.util.Calendar cal)
time
- Java Time objectcal
- Java Calendar object which encapsulates the timezone
information of timepublic DATE(java.sql.Timestamp timestamp, java.util.Calendar cal)
timestamp
- Java Timestamp objectcal
- Java Calendar object which encapsulates the timezone
information of timestamppublic DATE(java.lang.String str)
str
- Java String objectpublic DATE(java.lang.String str, boolean lenient) throws java.text.ParseException
str
- Java String objectlenient
- Java Boolean variable
java.text.ParseException
public DATE(java.lang.String str, java.util.Calendar cal)
str
- Java String objectcal
- Java Calendar object which encapsulates the timezone
information for interpreting strpublic DATE(java.lang.Object obj) throws java.sql.SQLException
obj
- Object valueobj
- Object valueobj
- Object value
java.sql.SQLException
- if initialization is not allowedpublic DATE(java.lang.Object obj, java.util.Calendar cal) throws java.sql.SQLException
obj
- Object valuecal
- Calendar to useobj
- Object valueobj
- Object valuecal
- Calendar which encapsulates the timezone
information of obj
java.sql.SQLException
- if initialization is not allowedMethod Detail |
---|
public static java.sql.Date toDate(byte[] date)
date
- Oracle Date to be converted
public static java.sql.Time toTime(byte[] date)
date
- Oracle Date to be converted
public static java.sql.Timestamp toTimestamp(byte[] date)
date
- Oracle Date to be converted
public static java.sql.Date toDate(byte[] date, java.util.Calendar cal)
date
- Oracle Date to be convertedcal
- Calendar which encapsulates the timezone
information to be used to create Date object
public static java.sql.Time toTime(byte[] date, java.util.Calendar cal)
date
- Oracle Date to be convertedcal
- Calendar which encapsulates the timezone
information to be used to create the Time object
public static java.sql.Timestamp toTimestamp(byte[] date, java.util.Calendar cal)
date
- Oracle Date to be convertedcal
- Calendar which encapsulates the timezone
information to be used to create the Timestamp object
public static java.lang.String toString(byte[] bytes)
date
- a byte array
public byte[] toBytes()
public static byte[] toBytes(java.sql.Date date)
date
- java.sql.Date object to be converted.
public static byte[] toBytes(java.sql.Time time)
time
- java.sql.Time object to be converted.
public static byte[] toBytes(java.sql.Timestamp timestamp)
timestamp
- java.sql.Timestamp object to be converted.
public static byte[] toBytes(java.sql.Date date, java.util.Calendar cal)
date
- java.sql.Date object to be converted.cal
- java.util.Calendar object which encapsulates the
timezone information of date
public static byte[] toBytes(java.sql.Time time, java.util.Calendar cal)
time
- java.sql.Time object to be converted.cal
- java.util.Calendar object which encapsulates the
timezone information of time
public static byte[] toBytes(java.sql.Timestamp timestamp, java.util.Calendar cal)
timestamp
- java.sql.Timestamp object to be converted.cal
- java.util.Calendar object which encapsulates the
timezone information of date
public static byte[] toBytes(java.lang.String str)
str
- java.lang.String object to be converted.
public static byte[] toBytes(java.lang.String str, java.util.Calendar cal)
str
- java.lang.String object to be converted.cal
- java.util.Calendar object which encapsulates the
timezone information for interpreting str
public java.sql.Date dateValue()
dateValue
in class Datum
public java.sql.Time timeValue()
timeValue
in class Datum
public java.sql.Timestamp timestampValue()
timestampValue
in class Datum
public java.sql.Date dateValue(java.util.Calendar cal)
cal
- Calendar to use
public java.sql.Time timeValue(java.util.Calendar cal)
timeValue
in class Datum
cal
- Calendar to use
public java.sql.Timestamp timestampValue(java.util.Calendar cal)
timestampValue
in class Datum
cal
- Calendar to use
public java.lang.String stringValue()
stringValue
in class Datum
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object toJdbc()
toJdbc
in class Datum
public java.lang.Object makeJdbcArray(int arraySize)
makeJdbcArray
in class Datum
arraySize
- size of the array
public boolean isConvertibleTo(java.lang.Class cls)
isConvertibleTo
in class Datum
cls
- Class to convert to
public DATE addJulianDays(int julianDay, int julianSec) throws java.sql.SQLException
julianDay
- Number of Julian days to add to DATEjulianSec
- Number of seconds past midnight
java.sql.SQLException
- if Java implementation is not
availablepublic DATE addMonths(int months) throws java.sql.SQLException
months
- integral months to add to date
java.sql.SQLException
- if Java implementation is not
availablepublic void diffInJulianDays(DATE date, int[] julianDay, int[] julianSec) throws java.sql.SQLException
date
- Date to be subtracted.julianDay
- Number of Julian daysjulianSec
- Number of seconds past midnight
java.sql.SQLException
- if Java implementation is not
availablepublic NUMBER diffInMonths(DATE date) throws java.sql.SQLException
date
- Date to be subtracted.
java.sql.SQLException
- if Java implementation is not
availablepublic static DATE getCurrentDate() throws java.sql.SQLException
java.sql.SQLException
- if Java implementation is not
availablepublic static int checkValidity(byte[] date) throws java.sql.SQLException
date
- Date to be checked
BDA | Bad day: above range |
BDAL | Bad day: below range |
BMO | Bad month: above range |
BMOL | Bad month: below range |
BYR | Bad year: above range |
BYRL | Bad year: below range |
BHR | Bad hour: above range |
BHRL | Bad hour: below range |
BMN | Bad minute: above range |
BMNL | Bad minute: below range |
BSC | Bad second: above range |
BSCL | Bad second: below range |
MSD | Day is one of those "missing" from the year 1582 |
YR0 | Year zero does not exist |
BDT | Bad date format |
HRZERO | Zero valued hour |
MIZERO | Zero valued minute |
SEZERO | Zero valued second |
java.sql.SQLException
- if Java implementation is not
availablepublic static DATE fromJulianDays(int julianDay, int julianSec) throws java.sql.SQLException
julianDay
- Number of Julian daysjulianSec
- Number of seconds past midnight
java.sql.SQLException
- if Java implementation is not
availablepublic static DATE fromText(java.lang.String datestr, java.lang.String fmt, java.lang.String lang) throws java.sql.SQLException
datestr
- Input Date stringfmt
- Date Formatlang
- Input date language
String | Meaning |
---|---|
a.d. | B.C./A.D. indicator |
a.m. | A.M./P.M. indicator |
ad | BC/AD indicator |
am | AM/PM indicator |
b.c. | B.C./A.D. indicator |
bc | BC/AD indicator |
d | day of the week |
day | name of the day, spelled out |
dd | day of the month |
ddd | day of year |
dy | name of weekday abbreviated |
hh | hour representation in 12 hour format |
hh24 | hour representation in 24 hour format |
mi | minutes |
mm | two digit month representation |
mon | month abbreviation |
month | name of the month, spelled out |
p.m. | A.M./P.M. indicator |
pm | AM/PM indicator |
ss | two digit second representation |
Y | last digit of the year |
YY | last two digits of a year |
YYY | last three digits of a year |
YYYY | year |
" | all text in quotes is copied into the output string It is not possible to place a quote character into the output string. On input, literal text is a placeholder for another string of the same length |
/,%&@#.. | punctuation (non-alphanumeric characters) is treated exactly like a literal without the need for quotes. |
The Date format string not supported versus the C
library are:
String | Meaning |
---|---|
E | abbreviated era name |
EE | full era name |
FX | all date literals must be an exact match |
j | Julian day |
RM | Roman numeral month (I-XII) |
RR | Round year with two digits (on input, rounds the century up one if the year is <50 and the reference date is >= 50, and down one century if the year is >= 50 and the reference date is <50) |
RRRR | Round year (on input, accepts either four digit input or, for two digit input, rounds the century up one if the year is <50 and the reference date is >= 50, and down one century if the year is >= 50 and the reference date is <50) |
sssss | number of seconds past midnight |
sy,yyy | signed year (BC dates have "-" in front) |
syYYY | signed year (BC dates have "-" in front) |
Y,YYY | year with comma |
YEAR | year number spelled out |
Also parsing is strict i.e. spaces and literals should match the format string exactly. (except for a.d./b.c. the string should be ad/bc)
java.sql.SQLException
public DATE lastDayOfMonth() throws java.sql.SQLException
java.sql.SQLException
- if Java implementation is not
availablepublic static void numberToJulianDays(NUMBER num, int[] julianDay, int[] julianSec) throws java.sql.SQLException
num
- Oracle Number to convertjulianDay
- Number of Julian daysjulianSec
- Number of seconds past midnight
java.sql.SQLException
- if Java implementation is not
availablepublic DATE round(java.lang.String prec) throws java.sql.SQLException
prec
- precision to use while rounding
java.sql.SQLException
- if Java implementation is not
availablepublic DATE setDayOfWeek(int day) throws java.sql.SQLException
day
- day of the week the date needs to be advanced
java.sql.SQLException
- if Java implementation is not
availablepublic void toJulianDays(int[] julianDay, int[] julianSec) throws java.sql.SQLException
julianDay
- Number of Julian daysjulianSec
- Number of seconds past midnight
java.sql.SQLException
- if Java implementation is not
availablepublic NUMBER toNumber() throws java.sql.SQLException
java.sql.SQLException
- if Java implementation is not
availablepublic java.lang.String toText(java.lang.String fmt, java.lang.String lang) throws java.sql.SQLException
fmt
- date formatlang
- the NLS language the conversion is to be
performed in, null indicates use default.
java.sql.SQLException
- if Java implementation is not
available or an invalid format string is provided.public java.lang.String toText(byte[] pfmt, java.lang.String lang) throws java.sql.SQLException
pfmt
- date format parsed by parseFormatlang
- the NLS language the conversion is to be
performed in, null indicates use default.
java.sql.SQLException
- if Java implementation is not
available or an invalid format string is provided.public static byte[] parseFormat(java.lang.String fmt, java.lang.String lang) throws java.sql.SQLException
fmt
- date formatlang
- A String containing NLS Language and/or Territory
null indicates to use default.
java.sql.SQLException
- if the format string can not be parsed.public DATE truncate(java.lang.String prec) throws java.sql.SQLException
prec
- precision to use while truncating
java.sql.SQLException
- if Java implementation is not
availablepublic int compareTo(DATE date)
date
- input Oracle Date
|
Oracle JDBC API Reference 11g Release 2 ("11.2.0.3.0") |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |