Thejava.sql package contains the entire JDBC API. It first became part of the core
Java libraries with the 1.1 release. Classes new as of JDK 1.2 are indicated by the
“Availability” header. Deprecated methods are preceded by a hash (#) mark. New
JDK 1.2 methods in old JDK 1.1 classes are shown in bold. Figure 27-1 shows the
entirejava.sqlpackage.
Figure 27-1. The classes and interfaces of the java.sql package
KEY
Connection
java.util
java.sql
Object
Types
DriverManager
DriverPropertyInfo
DatabaseMetaData
Driver
Exception SQLException
ResultSet
ResultSetMetaData
Statement PreparedStatement CallableStatement
Date
Time
Time stamp
Date
java.lang
implements
extends
SQLWarning DataTruncation
CLASS
INTERFACE
DRAFT, 8/24/01
Copyright © 2001 O’Reilly & Associates, Inc.
Array
Synopsis
Class Name:java.sql.Array
Superclass:None
Immediate Subclasses: None
Interfaces Implemented: None
Availability: New as of JDK 1.2
Description
TheArrayinterface is a new addition to JDBC that supports SQL3 array objects.
The default duration of a reference to a SQL array is for the life of the transaction
in which it was created.
Class Summary
public interface Array {
Object getArray() throws SQLException;
Object getArray(Map map) throws SQLException;
Object getArray(long index, int count)
throws SQLException;
Object getArray(long index, int count, Map map)
throws SQLException;
int getBaseType() throws SQLException;
String getBaseTypeName() throws SQLException;
ResultSet getResultSet() throws SQLException;
ResultSet getResultSet(Map map) throws SQLException;
ResultSet getResultSet(long index, int count)
throws SQLException;
ResultSet getResultSet(long index, int count,
Map map) throws SQLException
}
54 trang |
Chia sẻ: tlsuongmuoi | Lượt xem: 2438 | Lượt tải: 1
Bạn đang xem trước 20 trang tài liệu The JDBC API, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
DRAFT, 8/24/01
533
Copyright © 2001 O’Reilly & Associates, Inc.
27
The JDB
The java.sql pack
Java libraries wi
“Availability” he
JDK 1.2 method
entire java.sql pac
Figure 27-1. The
KEY
java.util
j
Object
Exception
Date
java.lang
CLASS
INTERFACData
Dataclasses and interfaces of the java.sql package
ResultSet
ResultSetMeta
Time
Time stamp
implements
extends
EDriverPropertyInfo
SQLException
Statement PreparedStatement CallableStatement
Date
SQLWarning DataTruncationChapter 27
C API 27.
age contains the entire JDBC API. It first became part of the core
th the 1.1 release. Classes new as of JDK 1.2 are indicated by the
ader. Deprecated methods are preceded by a hash (#) mark. New
s in old JDK 1.1 classes are shown in bold. Figure 27-1 shows the
kage.
Connection
ava.sql
Types
DriverManager DatabaseMeta
Driver
DRAFT, 8/24/01
Array
Synopsis
Class Name:
Superclass:N
Immediate S
Interfaces Im
Availability:
Description
The Array interfa
The default dura
in which it was c
Class Summary
public interface Ar
Object getArray
Object getArray
Object getArray
throws SQLE
Object getArray
throws SQLE
int getBaseType
String getBaseT
ResultSet getRe
ResultSet getRe
ResultSet getRe
throws SQLE
ResultSet getRe
Ma
}
Object Methods
getArray( )
public Object getA
public Object getA
public Object getA
throws SQLExc
public Object getA
throws SQLExc
Description:
instead, into
but no matc
used. The tw
you to placejava.sql.Array
one
ubclasses: None
plemented: None
New as of JDK 1.2
ce is a new addition to JDBC that supports SQL3 array objects.
tion of a reference to a SQL array is for the life of the transaction
reated.
ray {
() throws SQLException;
(Map map) throws SQLException;
(long index, int count)
xception;
(long index, int count, Map map)
xception;
() throws SQLException;
ypeName() throws SQLException;
sultSet() throws SQLException;
sultSet(Map map) throws SQLException;
sultSet(long index, int count)
xception;
sultSet(long index, int count,
p map) throws SQLException
rray() throws SQLException
rray(Map map) throws SQLException
rray(long index, int count)
eption
rray(long index, int count, Map map)
eption
Place the contents of this SQL array into a Java language array or,
the Java type specified by a provided Map. If a map is specified
h is found in there, then the default mapping to a Java array is
o versions that accept an array index and element count enable
a subset of the elements in the array.Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
getBaseType( )
public int getBaseT
Description:
getBaseTypeNam
public String getB
Description:
getResultSet( )
public ResultSet g
public ResultSet g
throws SQLExc
public ResultSet g
throws SQLExc
public ResultSet g
M
throws SQLExc
Description:
appropriate,
or the speci
the first colu
is the actual
Blob
Synopsis
Class Name:
Superclass: N
Immediate S
Interfaces Im
Availability:
Description
The JDBC Blob
object” and is a
The value of us
without retrievin
object is only va
Class Summary
public interface Bl
InputStream get
byte[] getBytes(
throws SQLE
long length() thr
long position(byype() throws SQLException
Provides the JDBC type of the elements of this array.
e( )
aseTypeName() throws SQLException
Provides the SQL type name for the elements of this array.
etResultSet() throws SQLException
etResultSet(Map map)
eption
etResultSet(long index, int count)
eption
etResultSet(long index, int count,
ap map)
eption
Provides a result set that contains the array’s elements as rows. If
the elements are mapped using the type map for the connection,
fied type map if you pass one. Each row contains two columns:
mn is the index number (starting with 1), and the second column
value.
java.sql.Blob
one
ubclasses: None
plemented: None
New as of JDK 1.2
interface represents a SQL BLOB. BLOB stands for “binary large
relational database representation of a large piece of binary data.
ing a BLOB is that you can manipulate the BLOB as a Java object
g all of the data behind the BLOB from the database. A BLOB
lid for the duration of the transaction in which it was created.
ob {
BinaryStream() throws SQLException;
long pos, int count)
xception;
ows SQLException;
te[] pattern, long start)Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
throws SQLE
long position(Bl
throws SQLE
}
Object Methods
getBinaryStream
public InputStream
Description:
from the dat
getBytes( )
public byte[] getBy
throws SQLExc
Description:
part or in w
by specifyin
than the obj
length( )
public long length(
Description:
position( )
public long positio
throws SQLExc
public long positio
throws SQLExc
Description:
which the s
occur, then
CallableStatem
Synopsis
Class Name:
Superclass: j
Immediate S
Interfaces Im
Availability:
Description
The CallableState
vides support foxception;
ob pattern, long start)
xception;
( )
getBinaryStream() throws SQLException
Retrieves the data that makes up the binary object as a stream
abase.
tes(long pos, int count)
eption
Returns the data that makes up the underlying binary object in
hole as an array of bytes. You can get a subset of the binary data
g a nonzero starting index or by specifying a number of bytes less
ect’s length.
) throws SQLException
Provides the number of bytes that make up the BLOB.
n(byte[] pattern, long start)
eption
n(Blob pattern, long start)
eption
Searches this Blob for the specified pattern and returns the byte at
pecified pattern occurs within this Blob. If the pattern does not
this method will return -1.
ent
java.sql.CallableStatement
ava.sql.PreparedStatement
ubclasses: None
plemented: None
JDK 1.1
ment is an extension of the PreparedStatement interface that pro-
r SQL stored procedures. It specifies methods that handle the bind-Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
ing of output pa
dures should app
{? = call …}
{call …}
Each question m
syntax provides
parameters. The
mark holding th
Before executin
using the register
the various set m
Class Summary
public interface Ca
Array getArray(
BigDecimal getB
throws SQLE
#BigDecimal ge
throws SQLE
Blob getBlob(in
boolean getBool
byte getByte(int
byte[] getBytes(
Clob getClob(in
java.sql.Date ge
throws SQLE
java.sql.Date ge
double getDoub
float getFloat(in
int getInt(int ind
long getLong(in
Object getObjec
Object getObjec
throws SQLE
Ref getRef(int in
short getShort(in
String getString(
java.sql.Time ge
java.sql.Time ge
throws SQLE
java.sql.Timesta
throws SQLE
java.sql.Timesta
throws SQLE
void registerOut
throws SQLE
void registerOut
inrameters. JDBC prescribes a standard form in which stored proce-
ear independent of the DBMS being used. The format is:
ark is a place holder for an input or output parameter. The first
for a single result parameter. The second syntax has no result
parameters are referred to sequentially with the first question
e place for parameter 1.
g a stored procedure, all output parameters should be registered
OutParameter() method. You then bind the input parameters using
ethods, and then execute the stored procedure.
llableStatement extends PreparedStatement {
int index) throws SQLException;
igDecimal(int index)
xception;
tBigDecimal(int index, int scale)
xception;
t index) throws SQLException;
ean(int index) throws SQLException;
index) throws SQLException;
int index) throws SQLException;
t index) throws SQLException;
tDate(int index, Calendar cal)
xception;
tDate(int index) throws SQLException;
le(int index) throws SQLException;
t index) throws SQLException;
ex) throws SQLException;
t index) throws SQLException;
t(int index) throws SQLException;
t(int index, Map map)
xception;
dex) throws SQLException;
t index) throws SQLException;
int index) throws SQLException;
tTime(int index) throws SQLException;
tTime(int index, Calendar cal)
xception;
mp getTimestamp(int index)
xception;
mp getTimestamp(int index,
Calendar cal)
xception;
Parameter(int index, int type)
xception;
Parameter(int index, int type,
t scale)Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
throws SQLE
void registerOut
S
throws SQLE
boolean wasNul
}
Object Methods
getBigDecimal( )
public BigDecima
throws SQLExc
#public BigDecim
throws SQLExc
Description:
ter as a Java
is a nonneg
decimal. Par
getArray( ), getB
getFloat( ), getIn
public Array getA
throws SQLExc
public Blob getBlo
public boolean get
public byte getByt
public byte[] getBy
public Clob getClo
public double getD
public float getFlo
public int getInt(in
public long getLon
public Ref getRef(
public short getSho
public String getSt
Description:
ment as the
getDate( ), getTim
public Date getDa
public Date getDa
throws SQLExc
public Time getTim
public Time getTim
throws SQLExc
public Timestamp
throws SQLExc
public Timestamp
throws SQLExc
Description:
suitable toxception;
Parameter(int index, int type,
tring typename)
xception;
l() throws SQLException;
l getBigDecimal(int index)
eption
al getBigDecimal(int index, int scale)
eption
Returns the value of the parameter specified by the index parame-
BigDecimal with a scale specified by the scale argument. The scale
ative number representing the number of digits to the right of the
ameter indices start at 1; parameter 1 is thus index 1.
lob( ), getBoolean( ), getByte( ), getBytes( ), getClob( ), getDouble( ),
t( ), getLong( ), getRef( ), getShort( ), and getString( )
rray(int index)
eption
b(int index) throws SQLException
Boolean(int index) throws SQLException
e(int index) throws SQLException
tes(int index) throws SQLException
b(int index) throws SQLException
ouble(int index) throws SQLException
at(int index) throws SQLException
t index) throws SQLException
g(int index) throws SQLException
int index) throws SQLException
rt(int index) throws SQLException
ring(int index) throws SQLException
Returns the value of the parameter specified by the index argu-
Java datatype indicated by the method name.
e( ), and getTimestamp( )
te(int index) throws SQLException
te(int index, Calendar cal)
eption
e(int index) throws SQLException
e(int index, Calendar cal)
eption
getTimestamp(int index)
eption
getTimestamp(int index, Calendar cal)
eption
JDBC provides refinements on the basic java.util.Date object more
database programming. These methods provide ways to accessCopyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
return value
The new JD
getObject( )
public Object getO
public Object getO
throws SQLExc
Description:
the specified
driver choos
this parame
map.
registerOutParam
public void registe
throws SQLExc
public void registe
throws SQLExc
public void registe
throws SQLExc
Description:
you must re
java.sql.Type o
specifies the
to register. T
that require
sponding ge
new to JDK
types.
wasNull( )
public boolean wa
Description:
method will
Clob
Synopsis
Class Name:
Superclass: N
Immediate S
Interfaces Im
Availability:s from a CallableStatement as a Date, Time, or Timestamp object.
K 1.2 variants allow you to specify a Calendar.
bject(int index) throws SQLException
bject(int index, Map map)
eption
Like the other getXXX() methods, this method returns the value of
output parameter. In the case of getObject(), however, the JDBC
es the Java class that corresponds to the SQL type registered for
ter using registerOutParameter() or according to the specified type
eter( )
rOutParameter(int index, int type)
eption
rOutParameter(int index, int type,
int scale)
eption
rOutParameter(int index, int type,
String typename)
eption
Before executing any stored procedure using a CallableStatement,
gister each of the output parameters. This method registers the
f an output parameter for a stored procedure. The first parameter
output parameter being registered and the second the java.sql.Type
he three-argument version of this method is for BigDecimal types
a scale. You later read the output parameters using the corre-
tXXX() method or getObject(). The third version of this method is
1.2 and provides a way to map REF SQL types or custom SQL
sNull() throws SQLException
If the last value you read using a getXXX() call was SQL NULL, this
return true.
java.sql.Clob
one
ubclasses: None
plemented: None
New as of JDK 1.2Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
Description
CLOB is a SQL3
represents a very
resents text stor
type as opposed
can be retrieved
Class Summary
public interface Cl
InputStream get
Reader getChara
String getSubStr
throws SQLE
long length() thr
long position(St
throws SQLE
long position(Cl
throws SQLE
}
Object Methods
getAsciiStream( )
public InputStream
Description:
stream.
getCharacterStre
public Reader getC
Description:
stream.
getSubString( )
public String getSu
throws SQLExc
Description:
to the numb
length( )
public long length(
Description:
position( )
public long positio
throws SQLExc
public long positio
throws SQLExc
Description:
start point. Itype that stands for “character large object.” Like a BLOB, a CLOB
large chunk of data in the database. Unlike a BLOB, a CLOB rep-
ed using some sort of character encoding. The point of a CLOB
to a CHAR or VARCHAR type is that CLOB data, like BLOB data,
as a stream instead of all at once.
ob {
AsciiStream() throws SQLException;
cterStream() throws SQLException;
ing(long pos, int count)
xception;
ows SQLException;
ring pattern, long start)
xception;
ob pattern, long start)
xception;
getAsciiStream() throws SQLException
Provides access to the data that makes up this Clob via an ASCII
am( )
haracterStream() throws SQLException
Provides access to the data that makes up this Clob via a Unicode
bString(long pos, int count)
eption
Returns a substring of the Clob starting at the named position up
er of character specified by the count value.
) throws SQLException
Provides the number of characters that make up the Clob.
n(String pattern, long start)
eption;
n(Clob pattern, long start)
eption;
Searches the Clob for the specified pattern starting at the specified
f the pattern is found within the Clob, the index at which the pat-Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
tern first oc
method retu
Connection
Synopsis
Class Name:
Superclass: N
Immediate S
Interfaces Im
Availability:
Description
The Connection c
an application w
handles the tran
ment is committ
to turn off this
expressly send c
Class Summary
public interface Co
static public fina
static public fina
static public fina
static public fina
static public fina
void clearWarni
void close() thro
void commit() th
Statement create
Statement create
throws SQLE
boolean getAuto
String getCatalo
Map getTypeM
DatabaseMetaD
int getTransactio
SQLWarning ge
boolean isClose
boolean isReadO
String nativeSQ
CallableStateme
throws SQLE
CallableStateme
throws SQLEcurs is returned. If it does not exist within the Clob, then this
rns -1.
java.sql.Connection
one
ubclasses: None
plemented: None
JDK 1.1
lass is the JDBC representation of a database session. It provides
ith Statement objects (and its subclasses) for that session. It also
saction management for those statements. By default, each state-
ed immediately upon execution. You can use the Connection object
Autocommit feature for the session. In that event, you must
ommits, or any statements executed will be lost.
nnection {
l int TRANSACTION_NONE;
l int TRANSACTION_READ_UNCOMMITTED;
l int TRANSACTION_READ_COMMITTED;
l int TRANSACTION_REPEATABLE_READ;
l int TRANSACTION_SERIALIZABLE;
ngs() throws SQLException;
ws SQLException;
rows SQLException;
Statement() throws SQLException;
Statement(int type, int concur)
xception;
Commit() throws SQLException;
g() throws SQLException;
ap() throws SQLException;
ata getMetaData() throws SQLException;
nIsolation() throws SQLException;
tWarnings() throws SQLException;
d() throws SQLException;
nly() throws SQLException;
L(String sql) throws SQLException;
nt prepareCall(String sql)
xception;
nt prepareCall(String sql, int type,
int concur)
xception;Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
PreparedStatem
throws SQLE
PreparedStatem
throws SQLE
void rollback() t
void setAutoCom
void setCatalog(
void setReadOn
void setTransact
throws SQLE
void setTypeMa
}
Class Attributes
TRANSACTION_N
static public final i
Description:
TRANSACTION_R
static public final i
Description:
one transact
TRANSACTION_R
static public final i
Description:
ring. In othe
action are
change com
TRANSACTION_R
static public final i
Description:
peatable rea
row, a seco
row, getting
Object Methods
clearWarnings( )
public void clearW
Description:
getWarnings()
close( )
public void close()ent prepareStatement(String sql)
xception;
ent prepareStatement(String sql,
int type,
int concur)
xception;
hrows SQLException;
mit(boolean ac) throws SQLException;
String catalog) throws SQLException;
ly(boolean ro) throws SQLException;
ionIsolation(int level)
xception;
p(Map map) throws SQLException;
ONE
nt TRANSACTION_NONE
Transactions are not supported.
EAD_UNCOMMITTED
nt TRANSACTION_READ_UNCOMMITTED
This transaction isolation level allows uncommitted changes by
ion to be readable by other transactions.
EAD_COMMITTED
nt TRANSACTION_READ_COMMITTED
This transaction isolation level prevents dirty reads from occur-
r words, changes by a TRANSACTION_READ_COMMITTED trans-
invisible to other transactions until the transaction making the
mits those changes.
EPEATABLE_READ
nt TRANSACTION_REPEATABLE_READ
This transaction isolation level prevents dirty reads and nonre-
ds. A nonrepeatable read is one where one transaction reads a
nd transaction alters the row, and the first transaction rereads the
different values the second time.
arnings() throws SQLException
Clears out all the warnings associated with this Connection so that
will return null until a new warning is reported.
throws SQLExceptionCopyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
Description:
connections
method is a
best to manu
commit( )
public void comm
Description:
ments assoc
issued. It sh
changes mad
createStatement(
public Statement c
public Statement c
throws SQLExc
Description:
Connection se
whose Resul
getAutoCommit(
public boolean get
public void setAut
throws SQLExc
Description:
Autocommit
cation may i
a single tran
Autocommit
rollback() de
When in Au
ment compl
statements r
been retriev
result sets, t
been retriev
getCatalog( ) and
public String getC
public void setCata
Description:
subspace of
not support
getMetaData( )
public DatabaseMThis method manually releases all resources (such as network
and database locks) associated with a given JDBC Connection. This
utomatically called when garbage collection occurs; however, it is
ally close a Connection once you are done with it.
it() throws SQLException
This method makes permanent the changes created by all state-
iated with this Connection since the last commit or rollback was
ould only be used when Autocommit is off. It does not commit
e by statements associated with other Connection objects.
)
reateStatement() throws SQLException
reateStatement(int type, int concur)
eption
This method creates a Statement object associated with this
ssion. The no argument version of this method creates a Statement
tSet instances are type forward-only and read-only concurrency.
) and setAutoCommit( )
AutoCommit() throws SQLException
oCommit(boolean ac)
eption
By default, all Connection objects are in Autocommit mode. With
mode on, each statement is committed as it is executed. An appli-
nstead choose to manually commit a series of statements together as
saction. In this case, you use the setAutoCommit() method to turn
off. You then follow your statements with a call to commit() or
pending on the success or failure of the transaction.
tocommit mode, a statement is committed either when the state-
etes or when the next statement is executed, whichever is first. For
eturning a ResultSet, the statement completes when the last row has
ed or the ResultSet has been closed. If a statement returns multiple
he commit occurs when the last row of the last ResultSet object has
ed.
setCatalog( )
atalog() throws SQLException
log(String catalog) throws SQLException
If a driver supports catalogs, then you use setCatalog() to select a
the database with the specified catalog name. If the driver does
catalogs, it will ignore this request.
etaData getMetaData() throws SQLExceptionCopyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
Description:
base’s tables
to the datab
statements a
DatabaseMetaD
getTransactionIs
public int getTrans
public void setTran
throws SQLExc
Description:
using one o
called T
TRANSACTI
getTypeMap( ) an
public Map getTyp
public void setTyp
Description:
ping for SQ
with this con
getWarnings( )
public SQLWarnin
Description:
this Connectio
isClosed( )
public boolean isC
Description:
isReadOnly( ) an
public boolean isR
public void setRea
Description:
setReadOnly()
only mode
while in the
nativeSQL( )
public String nativ
Description:
by JDBC. Th
JDBC SQL st
prepareCall( )
public CallableStaThe DatabaseMetaData class provides methods that describe a data-
, SQL support, stored procedures, and other information relating
ase and this Connection, which are not directly related to executing
nd retrieving result sets. This method provides an instance of the
ata class for this Connection.
olation( ) and setTransactionIsolation( )
actionIsolation() throws SQLException
sactionIsolation(int level)
eption
Sets the Connection object’s current transaction isolation level
f the class attributes for the Connection interface. Those levels are
RANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED,
ON_READ_COMMITTED, and TRANSACTION_REPEATABLE_READ.
d setTypeMap( )
eMap() throws SQLException
eMap(Map map) throws SQLException
You can use these methods to define or retrieve a custom map-
L structured types and distinct types for all statements associated
nection.
g getWarnings() throws SQLException
Returns the first warning in the chain of warnings associated with
n object.
losed() throws SQLException
Returns true if the Connection has been closed.
d setReadOnly( )
eadOnly() throws SQLException
dOnly(boolean ro) throws SQLException
Some databases can optimize for read-only database access. The
method provides you with a way to put a Connection into read-
so that those optimizations occur. You cannot call setReadOnly()
middle of a transaction.
eSQL(String sql) throws SQLException
Many databases may not actually support the same SQL required
is method allows an application to see the native SQL for a given
ring.
tement prepareCall(String sql)Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
throws SQLExc
public CallableSta
throws SQLExc
Description:
CallableStatem
ferred way o
of this meth
forward-only
prepareStatemen
public PreparedSta
throws SQLExc
public PreparedSta
throws SQLExc
Description:
Connection se
statements.
PreparedStatem
concurrency
rollback( )
public void rollbac
Description:
nection sinc
make those
statements t
commit is of
DatabaseMeta
Synopsis
Class Name:
Superclass: N
Immediate S
Interfaces Im
Availability:
Description
This class provid
object is conneception
tement prepareCall(String sql,
int type,
int concur)
eption
Given a particular SQL string, this method creates a
ent object associated with this Connection session. This is the pre-
f handling stored procedures. The default (no argument) version
od provides a CallableStatement whose ResultSet instances are type
and read-only concurrency.
t( )
tement prepareStatement(String sql)
eption
tement prepareStatement(String sql,
int type,
int concur)
eption
Provides a PreparedStatement object to be associated with this
ssion. This is the preferred way of handling precompiled SQL
The default (no argument) version of this method provides a
ent whose ResultSet instances are type forward-only and read-only
.
k() throws SQLException
Aborts all changes made by statements associated with this Con-
e the last time a commit or rollback was issued. If you want to
changes at a later time, your application will have to reexecute the
hat made those changes. This should be used only when auto-
f.
Data
java.sql.DatabaseMetaData
one
ubclasses: None
plemented: None
New as of JDK 1.1
es a lot of information about the database to which a Connection
ted. In many cases, it returns this information in the form of JDBCCopyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
ResultSet objects.
DatabaseMetaData
DatabaseMetaData
within the String
string of 0 or mo
to methods in pl
teria should be d
Class Summary
public interface Da
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public fina
static public finaFor databases that do not support a particular kind of metadata,
will throw an SQLException.
methods take string patterns as arguments where specific tokens
are interpreted to have a certain meaning. % matches any sub-
re characters and _ matches any one character. You can pass null
ace of string pattern arguments; this means that the argument’s cri-
ropped from the search.
tabaseMetaData {
l int bestRowTemporary;
l int bestRowTransaction;
l int bestRowSession;
l int bestRowUnknown;
l int bestRowNotPseudo;
l int bestRowPseudo;
l int columnNoNulls;
l int columnNullable;
l int columnNullableUnknown;
l int importedKeyCascade;
l int importedKeyRestrict;
l int importedKeySetNull;
l int importedKeyNoAction;
l int importedKeySetDefault;
l int importedKeyInitiallyDeferred;
l int importedKeyInitiallyImmediate;
l int importedKeyNotDeferrable;
l int procedureResultUnknown;
l int procedureNoResult;
l int procedureReturnsResult;
l int procedureColumnUnknown;
l int procedureColumnIn;
l int procedureColumnOut;
l int procedureColumnReturn;
l int procedureColumnResult;
l int procedureNoNulls;
l int procedureNullable;
l int procedureNullableUnknown;
l short tableIndexStatistic;
l short tableIndexClustered;
l short tableIndexHashed;
l short tableIndexOther;
l int typeNoNulls;
l int typeNullable;
l int typeNullableUnknown;
l int typePredNone;
l int typePredChar;
l int typePredBasic;
l int typeSearchable;
l int versionColumnUnknown;
l int versionColumnNotPseudo;Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
static public fina
boolean allProce
throws SQLE
boolean allTable
boolean dataDef
throws SQLE
boolean dataDef
throws SQLE
ResultSet getBe
String schema
boolean nullab
throws SQLE
ResultSet getCa
String getCatalo
String getCatalo
ResultSet getCo
String spat,
String cpat)
ResultSet getCo
String spat,
String cpat)
ResultSet getCro
String prim
String foreig
String foreig
String getDataba
String getDataba
throws SQLE
int getDefaultTr
throws SQLE
int getDriverMa
int getDriverMin
String getDriver
String getDriver
ResultSet getEx
String schema
throws SQLE
String getExtraN
String getIdentif
ResultSet getIm
String schema
ResultSet getInd
String schema
boolean appro
int getMaxBinar
int getMaxCatal
int getMaxCharL
int getMaxcnam
int getMaxColum
int getMaxColum
int getMaxColum
int getMaxColum
int getMaxColuml int versionColumnPseudo;
duresAreCallable()
xception;
sAreSelectable() throws SQLException;
initionCausesTransactionCommit()
xception;
initionIgnoredInTransactions()
xception;
stRowIdentifier(String catalog,
, String table, int scope,
le)
xception;
talogs() throws SQLException;
gSeparator() throws SQLException;
gTerm() throws SQLException;
lumnPriveleges(String catalog,
String table,
throws SQLException;
lumns(String catalog,
String tpat,
throws SQLException;
ssReference(String primaryCatalog,
arySchema, String primaryTable,
nCatalog, String foreignSchema,
nTable) throws SQLException;
seProductName() throws SQLException;
seProductVersion()
xception;
ansactionIsolation()
xception;
jorVersion();
orVersion();
Name() throws SQLException;
Version() throws SQLException;
portedKeys(String catalog,
, String table)
xception;
ameCharacters() throws SQLException;
ierQuoteString() throws SQLException;
portedKeys(String catalog,
, String table) throws SQLException;
exInfo(String catalog,
, String table, boolean unique,
ximate) throws SQLException;
yLiteralLength() throws SQLException;
ogNameLength() throws SQLException;
iteralLength() throws SQLException;
eLength() throws SQLException;
nsInGroupBy() throws SQLException;
nsInIndex() throws SQLException;
nsInOrderBy() throws SQLException;
nsInSelect() throws SQLException;
nsInTable() throws SQLException;Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
int getMaxConn
int getMaxIndex
int getMaxProce
throws SQLE
int getMaxRowS
int getMaxRowS
throws SQLE
int getMaxSchem
int getMaxState
int getMaxState
int getMaxTable
int getMaxTable
int getMaxUserN
String getNume
ResultSet getPri
String schema
ResultSet getPro
String scheme
String cnameP
String getProced
ResultSet getPro
String schema
throws SQLE
public abstract R
public abstract S
String getSearch
String getSQLK
String getStringF
String getSystem
ResultSet getTa
String schema
throws SQLE
ResultSet getTa
ResultSet getTa
String schema
String types[])
String getTimeD
ResultSet getTy
String getURL()
String getUserN
ResultSet getVe
String schema
boolean isCatalo
boolean isReadO
boolean nullPlus
boolean nullsAr
boolean nullsAr
boolean nullsAr
boolean nullsAr
boolean storesL
throws SQLE
boolean storesL
throws SQLE
boolean storesMections() throws SQLException;
Length() throws SQLException;
dureNameLength()
xception;
ize() throws SQLException;
izeIncludeBlobs()
xception;
aNameLength() throws SQLException;
mentLength() throws SQLException;
ments() throws SQLException;
NameLength() throws SQLException;
sInSelect() throws SQLException;
ameLength() throws SQLException;
ricFunctions() throws SQLException;
maryKeys(String catalog,
, String table) throws SQLException;
cedureColumns(String catalog,
Pattern, String procedureNamePattern,
attern) throws SQLException;
ureTerm() throws SQLException;
cedures(String catalog,
Pattern, String procedureNamePattern)
xception;
esultSet getSchemas() throws SQLException;
tring getSchemaTerm() throws SQLException;
StringEscape() throws SQLException;
eywords() throws SQLException;
unctions() throws SQLException;
Functions() throws SQLException;
blePriveleges(String catalog,
Pattern, String tableNamePattern)
xception;
bleTypes() throws SQLException;
bles(String catalog,
Pattern, String tableNamePattern,
throws SQLException;
ateFunctions() throws SQLException;
peInfo() throws SQLException;
throws SQLException;
ame() throws SQLException;
rsionColumns(String catalog,
, String table) throws SQLException;
gAtStart() throws SQLException;
nly() throws SQLException;
NonNullIsNull() throws SQLException;
eSortedHigh() throws SQLException;
eSortedLow() throws SQLException;
eSortedAtStart() throws SQLException;
eSortedAtEnd() throws SQLException;
owerCaseIdentifiers()
xception;
owerCaseQuotedIdentifiers()
xception;
ixedCaseIdentifiers()Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
throws SQLE
boolean storesM
throws SQLE
boolean storesU
throws SQLE
boolean storesU
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
boolean support
throws SQLE
boolean support
throws SQLE
boolean supppor
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
boolean support
boolean support
throws SQLE
boolean support
boolean support
throws SQLE
boolean
supportsDataDe
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
boolean support
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLException;
ixedCaseQuotedIdentifiers()
xception;
pperCaseIdentifiers()
xception;
pperCaseQuotedIdentifiers()
xception;
sAlterTableWithAddColumn()
xception;
sAlterTableWithDropColumn()
xception;
sANSI92FullSQL() throws SQLException;
sANSI92IntermediateSQL()
xception;
sCatalogsInDataManipulation()
xception;
tsCatalogsInIndexDefinitions()
xception;
sCatalogsInPrivelegeDefinitions()
xception;
sCatalogsInProcedureCalls()
xception;
sCatalogsInTableDefinitions()
xception;
sColumnAliasing() throws SQLException;
sConvert() throws SQLException;
sConvert(int fromType, int toType)
xception;
sCoreSQLGrammar() throws SQLException;
sCorrelatedSubqueries()
xception;
finitionAndDataManipulationTransactions()
xception;
sDataManipulationTransactionsOnly()
xception;
sDifferentTableCorrelationNames()
xception;
sExpressionsInOrderBy()
xception;
sExtendedSQLGrammar()
xception;
sFullOuterJoins() throws SQLException;
sGroupBy() throws SQLException;
sGroupByBeyondSelect()
xception;
sGroupByUnrelated()
xception;
sIntegrityEnhancementFacility()
xception;
sLikeEscapeClause()
xception;
sLimitedOuterJoins()
xception;Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean support
throws SQLE
boolean supportsMinimumSQLGrammar()
xception;
sMixedCaseIdentifiers()
xception;
sMixedCaseQuotedIdenfitiers()
xception;
sMultipleResultSets()
xception;
sMultipleTransactions()
xception;
sNonNullableColumns()
xception;
sOpenCursorsAcrossCommit()
xception;
sOpenCursorsAcrossRollback()
xception;
sOpenStatementsAcrossCommit()
xception;
sOpenStatementsAcrossRollback()
xception;
sOrderByUnrelated()
xception;
sOuterJoins() throws SQLException;
sPositionedDelete()
xception;
sPositionedUpdate()
xception;
sSchemasInDataManipulation()
xception;
sSchemasInIndexDefinitions()
xception;
sSchemasInPrivelegeDefinitions()
xception;
sSchemasInProcedureCalls()
xception;
sSchemasInTableDefinitions()
xception;
sSelectForUpdate()
xception;
sStoredProcedures()
xception;
sSubqueriesInComparisons()
xception;
sSubqueriesInExists()
xception;
sSubqueriesInIns()
xception;
sSubqueriesInQuantifieds()
xception;
sTableCorrelationNames()
xception;
sTransactionIsolationLevel(int level)
xception;
sTransactions() throws SQLException;Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
boolean support
boolean support
boolean usesLoc
throws SQLE
boolean usesLoc
}
Date
Synopsis
Class Name:
Superclass: j
Immediate S
Interfaces Im
Availability:
Description
This class deals
cifically worries
Class Summary
public class Date e
static public Dat
#public Date(int
public Date(long
public void setT
public String toS
}
Class Methods
valueOf( )
static public Date v
Description:
sponding in
Object Construct
Date( )
public Date(long d
#public Date(int ye
Description:
Date is to us
fies the num
tive number
cated constr
respect to casUnion() throws SQLException;
sUnionAll() throws SQLException;
alFilePerTable()
xception;
alFiles() throws SQLException;
java.sql.Date
ava.util.Date
ubclasses: None
plemented: None
JDK 1.1
with a subset of functionality found in the java.util.Date class. It spe-
only about days and ignores hours, minutes, and seconds.
xtends java.util.Date {
e valueOf(String s);
year, int month, int day);
date);
ime(long date);
tring();
alueOf(String s)
Given a String in the form of yyyy-mm-dd, this will return a corre-
stance of the Date class representing that date.
ors
ate)
ar, int month, int day)
Constructs a new Date instance. The proper way to construct a
e the new JDK 1.2 Date(long) constructor. The date argument speci-
ber of milliseconds since 1 January 1970 00:00:00 GMT. A nega-
represents the milliseconds before that date. The second, depre-
uctor naturally should never be used since it is ambiguous with
lendar and time zone.Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
Object Methods
setTime( )
public void setTim
Description:
number of m
ber represen
toString( )
public String toStr
Description: P
Driver
Synopsis
Class Name:
Superclass: N
Immediate S
Interfaces Im
Availability:
Description
This class repres
should create an
class. This allow
to load a driver.
The Driver objec
more databases
DriverManager wi
The first Driver to
Class Summary
public interface Dr
boolean accepts
Connection conn
throws SQLE
int getMajorVer
int getMinorVer
DriverPropertyI
throws SQLE
boolean jdbcCom
}e(long date)
Sets the time represented by this Date object to the specified
illiseconds since 1 January 1970 00:00:00 GMT. A negative num-
ts the milliseconds before that date.
ing()
rovides a String representing this Date in the form yyyy-mm-dd.
java.sql.Driver
one
ubclasses: None
plemented: None
JDK 1.1
ents a specific JDBC implementation. When a Driver is loaded, it
instance of itself and register that instance with the DriverManager
s applications to create instances of it using the Class.forName() call
t then provides the ability for an application to connect to one or
. When a request for a specific database comes through, the
ll pass the data source request to each Driver registered as a URL.
connect to the data source using that URL will be used.
iver {
URL(String url) throws SQLException;
ect(String url, Properties info)
xception;
sion();
sion();
nfo[] getPropertyInfo(String url,
Properties info)
xception;
pliant();Copyright © 2001 O’Reilly & Associates, Inc.
Object Methods
acceptsURL( )
public boolean acc
Description:
used by this
connect( )
public Connection
throws SQLExc
Description:
Property info
URL is not
URL, but an
should be th
getMajorVersion
public int getMajo
Description:
getMinorVersion
public int getMino
Description:
getPropertyInfo(
public DriverPrope
throws SQLExc
Description:
which prope
enter values
jdbcCompliant( )
public boolean jdb
Description:
ance tests. T
API and full
DriverManage
Synopsis
Class Name:
Superclass: j
Immediate S
Interfaces Im
Availability:DRAFT, 8/24/01
eptsURL(String url) throws SQLException
Returns true if the specified URL matches the URL subprotocol
driver.
connect(String url, Properties info)
eption
This method attempts a connect using the specified URL and
rmation (usually containing the user name and password). If the
right for this driver, connect() simply returns null. If it is the right
error occurs during the connection process, an SQLException
rown.
( )
rVersion()
Returns the major version number for the driver.
( )
rVersion()
Returns the minor version number for the driver.
)
rtyInfo[] getPropertyInfo(String url,
Properties info)
eption;
This method allows GUI-based RAD environments to find out
rties the driver needs on connect so that it can prompt a user to
for those properties.
cCompliant()
A Driver can return true here only if it passes the JDBC compli-
his means that the driver implementation supports the full JDBC
SQL 92 Entry Level.
r
java.sql.DriverManager
ava.lang.Object
ubclasses: None
plemented: None
JDK 1.1Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
Description
The DriverManage
Upon initializatio
thus specify any
tion on the comm
During program
DriverManager by
URL to find an a
getConnection().
The DriverManage
dard Extension
base connection
Class Summary
public class Driver
static void dereg
throws SQLE
static public syn
Properties info
static public syn
String user, St
static public syn
throws SQLE
static public Dri
static public Enu
static public int g
#static public Pr
static public Prin
static public void
static public syn
throws SQL
#static public vo
static public v
static public void
}
Class Methods
deregisterDriver(
static public void d
Description:
getConnection( )
static public synch
Properties info
static public synch
String user, St
static public synchr holds the master list of registered JDBC drivers for the system.
n, it loads all classes specified in the jdbc.drivers property. You can
runtime information about the database being used by an applica-
and line.
execution, other drivers may register themselves with the
calling the registerDriver() method. The DriverManager uses a JDBC
pplication’s desired driver choice when requests are made through
r class is likely to disappear one day as the new JDBC 2.0 Stan-
provides a much more application-friendly way of getting a data-
.
Manager {
isterDriver(Driver driver)
xception;
chronized Connection getConnection(String url,
) throws SQLException;
chronized Connection getConnection(String url,
ring password) throws SQLException;
chronized Connection getConnection(String url)
xception;
ver getDriver(String url) throws SQLException;
meration getDrivers();
etLoginTimeout();
intStream getLogStream();
tWriter getLogWriter();
println(String message);
chronized void registerDriver(Driver driver)
Exception;
id setLogStream(PrintStream out);
oid setLogWriter(PrintWriter out);
setLoginTimeout(int seconds);
)
eregisterDriver(Driver driver) throws SQLException
Removes a Driver from the list of registered drivers.
ronized Connection getConnection(String url,
) throws SQLException
ronized Connection getConnection(String url,
ring password) throws SQLException
ronized Connection getConnection(String url)Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
throws SQLE
Description:
given. The D
for one tha
SQLException
method in th
getDriver( )
static public Drive
Description:
getDrivers( )
static public Enum
Description:
getLoginTimeout
static public int get
static public int set
Description:
can wait in a
getLogStream( ) a
#static public Print
#static public void
static public PrintW
static public void s
Description:
LogStream va
log writers
println( )
static public void p
Description:
registerDriver( )
static public synch
throws SQLE
Description:
the DriverMaxception
Establishes a connection to the data store represented by the URL
riverManager then looks through its list of registered Driver instances
t will handle the specified URL. If none is found, it throws an
. Otherwise it returns the Connection instance from the connect()
e Driver class.
r getDriver(String url) throws SQLException
Returns a driver than can handle the specified URL.
eration getDrivers()
Returns a list of all registered drivers.
( ) and setLoginTimeout( )
LoginTimeout()
LoginTimeout()
The login timeout is the maximum time in seconds that a driver
ttempting to log in to a database.
nd setLogStream( )
Stream getLogStream()
setLogStream(PrintStream out)
riter getLogWriter()
etLogWriter(PrintWriter out)
Sets the stream used by the DriverManager and all drivers. The
riant is the old JDK 1.1 version and should be avoided in favor of
rintln(String message)
Prints a message to the current log stream.
ronized void registerDriver(Driver driver)
xception
This method allows a newly loaded Driver to register itself with
nager class.Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
DriverPropert
Synopsis
Class Name:
Superclass: j
Immediate S
Interfaces Im
Availability:
Description
This class provid
base. Only deve
ods, simply a lis
Class Summary
public class Driver
public String[] c
public String des
public String nam
public boolean r
public String val
public DriverPro
}
Object Attributes
choices
public String[] cho
Description:
value for thi
description
public String descr
Description:
name
public String name
Description:
required
public boolean req
Description:
make a conn
value
public String value
Description:yInfo
java.sql.DriverPropertyInfo
ava.lang.Object
ubclasses: None
plemented: None
JDK 1.1
es information required by a driver in order to connect to a data-
lopment tools are likely ever to require this class. It has no meth-
t of public attributes.
PropertyInfo {
hoices;
cription;
e;
equired;
ue;
pertyInfo(String name, String value);
ices
A list of choices from which a user may be prompted to specify a
s property. This value can be null.
iption
A brief description of the property or null.
The name of the property.
uired
Indicates whether or not this property must be set in order to
ection.
The current value of the property or null if no current value is set.Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
Object Construct
DriverPropertyIn
public DriverPrope
Description:
attributes se
default value
PreparedState
Synopsis
Class Name:
Superclass: j
Immediate S
Interfaces Im
Availability:
Description
This class repres
Class Summary
public interface Pr
void addBatc
void clearParam
boolean execute
ResultSet execu
int executeUpda
ResultSetMet
void setArray(in
throws SQLE
void setAsciiStr
int length) thro
void setBigDeci
throws SQLE
void setBinaryS
int length) thro
void setBlob(int
void setBoolean
throws SQLE
void setByte(int
void setBytes(in
throws SQLE
void setCharacte
int length) thro
void setClob(int
void setDate(int
void setDate(int
throws SQLE
void setDouble(ors
fo( )
rtyInfo(String name, String value)
Constructs a new DriverPropertyInfo object with the name and value
t to the specified parameters. All other values are set to their
s.
ment
java.sql.PreparedStatement
ava.sql.Statement
ubclasses: java.sql.CallableStatement
plemented: None
JDK 1.1
ents a precompiled SQL statement.
eparedStatement extends Statement {
h() throws SQLException;
eters() throws SQLException;
() throws SQLException;
teQuery() throws SQLException;
te() throws SQLException;
aData getMetaData() throws SQLException;
t index, Array arr)
xception;
eam(int index, InputStream is,
ws SQLException;
mal(int index, BigDecimal d)
xception;
tream(int index, InputStream is,
ws SQLException;
index, Blob b) throws SQLException;
(int index, boolean b)
xception;
index, byte b) throws SQLException;
t index, byte[] bts)
xception;
rStream(int index, Reader rdr,
ws SQLException;
index, Clob c) throws SQLException;
index, Date d) throws SQLException;
index, Date d, Calendar cal)
xception;
int index, double x)Copyright © 2001 O’Reilly & Associates, Inc.
DRAFT, 8/24/01
throws SQLE
void setFloat(int
void setInt(int in
void setLong(in
void setNull(int
void setNull(int
throws SQLE
void setObject(i
throws SQLE
void setObject(i
throws SQLE
void setObject(i
int scale) throw
void setRef(int i
void setShort(in
void setString(in
throws SQLE
void setTime(in
void setTime(in
throws SQLE
void setTimesta
throws SQLE
void setTimesta
throws SQLE
#void setUnicod
int length) thro
}
Object Methods
addBatch( )
public void addBa
Description:
clearParameters
public abstract voi
Description:
value is set
clears all pa
execute( ), execu
public abstract boo
public abstract Res
public abstract int
Description:
you to exec
an update. I
The executeQ
for processinxception;
index, float f) throws SQLException;
dex, int x) throws SQLException;
t index, long x) throws SQLException;
index, int type) throws SQLException;
index, int type, String tname)
xception;
nt index, Object ob)
xception;
nt index, Object ob, int type)
xce
Các file đính kèm theo tài liệu này:
- my_ch27.pdf