MySQL Connector/J Documentation
Mark Matthews
Copyright (c) 2004, 2005 MySQL AB
This manual is NOT distributed under a GPL style license. Use of the
manual is subject to the following terms:
o Conversion to other formats is allowed, but the actual content may not
be altered or edited in any way.
o You may create a printed copy for your own personal use.
o For all other uses, such as selling printed copies or using (parts of)
the manual in another publication, prior written agreement from MySQL
AB is required.
Please email docs@mysql.com for more information or if you are interested
in doing a translation.
MySQL and the MySQL logo are (registered) trademarks of MySQL AB. Other
trademarks and registered trademarks referred to in this manual are the
property of their respective owners, and are used for identification
purposes only.
---------------------------------------------------------------------------
Table of Contents
1. [1]Developing Applications with MySQL and Java using Connector/J
1.1. [2]Introduction to JDBC Development
1.1.1. [3]Basic JDBC concepts
1.1.2. [4]Advanced JDBC Concepts
1.2. [5]Installing Connector/J
1.2.1. [6]Required Software Versions
1.2.2. [7]Upgrading from an Older Version
1.3. [8]JDBC Reference
1.3.1. [9]Driver/Datasource Class Names, URL
Syntax and Configuration Properties for
Connector/J
1.3.2. [10]JDBC API Implementation Notes
1.3.3. [11]Java, JDBC and MySQL Types
1.3.4. [12]Using Character Sets and Unicode
1.3.5. [13]Connecting Securely Using SSL
1.3.6. [14]Using Master/Slave Replication with
ReplicationConnection
1.4. [15]Using Connector/J with J2EE and Other Java
Frameworks
1.4.1. [16]General J2EE Concepts
1.4.2. [17]Using Connector/J with Tomcat
1.4.3. [18]Using Connector/J with JBoss
1.5. [19]Diagnosing Connector/J Problems
1.5.1. [20]Common Problems and Solutions
1.5.2. [21]How to Report Bugs or Problems
1.6. [22]Changelog
List of Tables
1.1. [23]Connection Properties
1.2. [24]Conversion Table
1.3. [25]MySQL Types to Java Types for ResultSet.getObject()
1.4. [26]MySQL to Java Encoding Name Translations
List of Examples
1.1. [27]Obtaining a Connection From the DriverManager
1.2. [28]Using java.sql.Statement to Execute a SELECT Query
1.3. [29]Stored Procedure Example
1.4. [30]Using Connection.prepareCall()
1.5. [31]Registering Output Parameters
1.6. [32]Setting CallableStatement Input Parameters
1.7. [33]Retrieving Results and Output Parameter Values
1.8. [34]Retrieving AUTO_INCREMENT Column Values using
Statement.getGeneratedKeys()
1.9. [35]Retrieving AUTO_INCREMENT Column Values using 'SELECT
LAST_INSERT_ID()'
1.10. [36]Retrieving AUTO_INCREMENT Column Values in Updatable ResultSets
1.11. [37]Setting the CLASSPATH Under UNIX
1.12. [38]Using a Connection Pool with a J2EE Application Server
1.13. [39]Example of transaction with retry logic
Chapter 1. Developing Applications with MySQL and Java using Connector/J
Table of Contents
1.1. [40]Introduction to JDBC Development
1.1.1. [41]Basic JDBC concepts
1.1.2. [42]Advanced JDBC Concepts
1.2. [43]Installing Connector/J
1.2.1. [44]Required Software Versions
1.2.2. [45]Upgrading from an Older Version
1.3. [46]JDBC Reference
1.3.1. [47]Driver/Datasource Class Names, URL Syntax and
Configuration Properties for Connector/J
1.3.2. [48]JDBC API Implementation Notes
1.3.3. [49]Java, JDBC and MySQL Types
1.3.4. [50]Using Character Sets and Unicode
1.3.5. [51]Connecting Securely Using SSL
1.3.6. [52]Using Master/Slave Replication with
ReplicationConnection
1.4. [53]Using Connector/J with J2EE and Other Java Frameworks
1.4.1. [54]General J2EE Concepts
1.4.2. [55]Using Connector/J with Tomcat
1.4.3. [56]Using Connector/J with JBoss
1.5. [57]Diagnosing Connector/J Problems
1.5.1. [58]Common Problems and Solutions
1.5.2. [59]How to Report Bugs or Problems
1.6. [60]Changelog
1.1. Introduction to JDBC Development
MySQL provides connectivity for client applications developed in the Java
programming language via a JDBC driver, which is called MySQL Connector/J.
MySQL Connector/J is a JDBC-3.0 "Type 4" driver, which means that is is
pure Java, implements version 3.0 of the JDBC specification, and
communicates directly with the MySQL server using the MySQL protocol.
This document is arranged for a beginning JDBC developer. If you are
already experienced with using JDBC, you might consider starting with the
section "[61]Installing Connector/J".
While JDBC is useful by itself, we would hope that if you are not familiar
with JDBC that after reading the first few chapters of this manual, that
you would avoid using "naked" JDBC for all but the most trivial problems
and consider using one of the popular persistence frameworks such as
[62]Hibernate , [63]Spring's JDBC templates or [64]Ibatis SQL Maps to do
the majority of repetitive work and heavier lifting that is sometimes
required with JDBC.
This chapter is not designed to be a complete JDBC tutorial. If you need
more information about using JDBC you might be interested in the following
online tutorials that are more in-depth than the information presented
here:
o [65]JDBC Basics - A tutorial from Sun covering beginner topics in JDBC
o [66]JDBC Short Course - A more in-depth tutorial from Sun and JGuru
1.1.1. Basic JDBC concepts
1.1.1.1. Connecting to MySQL using the DriverManager Interface
When you are using JDBC outside of an application server, the
DriverManager class manages the establishment of Connections.
The DriverManager needs to be told which JDBC drivers it should try to
make Connections with. The easiest way to do this is to use
Class.forName() on the class that implements the java.sql.Driver
interface. With MySQL Connector/J, the name of this class is
com.mysql.jdbc.Driver. With this method, you could use an external
configuration file to supply the driver class name and driver parameters
to use when connecting to a database.
The following section of Java code shows how you might register MySQL
Connector/J from the main() method of your application:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
public class LoadDriver {
public static void main(String[] args) {
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
}
}
After the driver has been registered with the DriverManager, you can
obtain a Connection instance that is connected to a particular database by
calling DriverManager.getConnection():
Example 1.1. Obtaining a Con
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
mysql-connector-java-3.0.17-ga (199个子文件)
CHANGES 54KB
DatabaseMetaData.class 61KB
Connection.class 45KB
ResultSet.class 39KB
PreparedStatement.class 35KB
MysqlIO.class 33KB
TimeUtil.class 30KB
UpdatableResultSet.class 24KB
Connection$UltraDevWorkAround.class 20KB
StatementRegressionTest.class 19KB
ResultSetRegressionTest.class 18KB
Statement.class 16KB
MysqlErrorNumbers.class 13KB
MetaDataRegressionTest.class 12KB
NonRegisteringDriver.class 11KB
ConnectionRegressionTest.class 11KB
StringRegressionTest.class 10KB
PreparedStatementWrapper.class 9KB
SQLError.class 9KB
ConnectionWrapper.class 9KB
Buffer.class 9KB
StatementsTest.class 8KB
StatementWrapper.class 8KB
Field.class 8KB
EscapeProcessor.class 8KB
StringUtils.class 8KB
StatementNodistTest.class 7KB
MetadataTest.class 7KB
CharsetMapping.class 7KB
LoadStorePerfTest.class 6KB
NumbersRegressionTest.class 6KB
ResultSetMetaData.class 6KB
DataSourceRegressionTest.class 6KB
MicroPerformanceRegressionTest.class 6KB
MysqlDataSource.class 5KB
BlobRegressionTest.class 5KB
RowDataDynamic.class 5KB
ConnectionTest.class 5KB
UpdatabilityTest.class 5KB
Util.class 5KB
Clob.class 5KB
CharsetTests.class 5KB
PooledConnectionRegressionTest.class 5KB
MysqlDefs.class 5KB
BlobTest.class 4KB
DataSourceTest.class 4KB
StandardSocketFactory.class 4KB
BaseTestCase.class 4KB
PreparedStatement$ParseInfo.class 4KB
Security.class 4KB
RetrievalPerfTest.class 4KB
DateTest.class 4KB
CompressedInputStream.class 3KB
Blob.class 3KB
TraversalTest.class 3KB
BasePerfTest.class 3KB
SingleByteCharsetConverter.class 3KB
Debug.class 3KB
MysqlPooledConnection.class 3KB
StressRegressionTest.class 3KB
MysqlDataSourceFactory.class 3KB
RowDataStatic.class 3KB
TransactionTest.class 2KB
BaseBugReport.class 2KB
EscapeProcessingTest.class 2KB
EscapeTokenizer.class 2KB
NumbersTest.class 2KB
SSLTest.class 2KB
StressRegressionTest$CreateThread.class 2KB
TimezoneDump.class 2KB
NamedPipeSocketFactory$NamedPipeSocket.class 2KB
NamedPipeSocketFactory.class 2KB
AppletRegressionTest.class 2KB
StressRegressionTest$ContentionThread.class 2KB
PooledConnectionRegressionTest$ConnectionListener.class 2KB
NamedPipeSocketFactory$RandomAccessFileInputStream.class 1KB
MiniAdmin.class 1KB
NamedPipeSocketFactory$RandomAccessFileOutputStream.class 1KB
MiniAdminTest.class 1KB
PreparedStatement$BatchParams.class 1KB
MysqlConnectionPoolDataSource.class 1KB
RowData.class 938B
WrapperBase.class 897B
PacketTooBigException.class 829B
AssertionFailedException.class 826B
WatchableOutputStream.class 794B
NotUpdatable.class 733B
RowDataDynamic$OperationNotSupportedException.class 708B
WatchableWriter.class 698B
Driver.class 669B
AppletRegressionTest$CustomAppletSecurity.class 634B
Util$RandStructcture.class 565B
LicenseConfiguration.class 502B
StressRegressionTest$BusyThread.class 480B
NotImplemented.class 392B
SocketFactory.class 380B
Driver.class 336B
PooledConnectionRegressionTest$1.class 214B
OutputStreamWatcher.class 201B
WriterWatcher.class 183B
共 199 条
- 1
- 2
wzhylzz
- 粉丝: 1
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0