Connector/J (JDBC) Reference
2075
thus requiring the data to be re-sent, using the
setBinaryStream()
,
setAsciiStream()
,
setUnicodeStream()
,
setBlob()
or
setClob()
method.
Consequently, to change the type of a parameter to a nonlarge one, you must call
clearParameters()
and set all parameters of the prepared statement again before it can be re-
executed.
• ResultSet
By default, ResultSets are completely retrieved and stored in memory. In most cases this is the
most efficient way to operate, and due to the design of the MySQL network protocol is easier to
implement. If you are working with ResultSets that have a large number of rows or large values, and
cannot allocate heap space in your JVM for the memory required, you can tell the driver to stream
the results back one row at a time.
To enable this functionality, create a
Statement
instance in the following manner:
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
The combination of a forward-only, read-only result set, with a fetch size of
Integer.MIN_VALUE
serves as a signal to the driver to stream result sets row-by-row. After this, any result sets created
with the statement will be retrieved row-by-row.
There are some caveats with this approach. You must read all of the rows in the result set (or close
it) before you can issue any other queries on the connection, or an exception will be thrown.
The earliest the locks these statements hold can be released (whether they be
MyISAM
table-level
locks or row-level locks in some other storage engine such as
InnoDB
) is when the statement
completes.
If the statement is within scope of a transaction, then locks are released when the transaction
completes (which implies that the statement needs to complete first). As with most other databases,
statements are not complete until all the results pending on the statement are read or the active
result set for the statement is closed.
Therefore, if using streaming results, process them as quickly as possible if you want to maintain
concurrent access to the tables referenced by the statement producing the result set.
• ResultSetMetaData
The
isAutoIncrement()
method only works when using MySQL servers 4.0 and newer.
• Statement
When using versions of the JDBC driver earlier than 3.2.1, and connected to server versions earlier
than 5.0.3, the
setFetchSize()
method has no effect, other than to toggle result set streaming as
described above.
Connector/J 5.0.0 and later include support for both
Statement.cancel()
and
Statement.setQueryTimeout()
. Both require MySQL 5.0.0 or newer server, and require a
separate connection to issue the
KILL QUERY
statement. In the case of
setQueryTimeout()
, the
implementation creates an additional thread to handle the timeout functionality.
Note
Failures to cancel the statement for
setQueryTimeout()
may manifest
themselves as
RuntimeException
rather than failing silently, as there
is currently no way to unblock the thread that is executing the query being
cancelled due to timeout expiration and have it throw the exception instead.
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...