日期:2014-05-16 浏览次数:20533 次
1.JDBC 创建CONNECTION 的两种方式
? 通过Class.forName()加载数据库驱动程序,然后再使用DriverManager.getConnection() 获取连接.
?
? 通过javax.sql.DataSource提供了另一种建立数据库连接的方式.通过JNDI服务器查询,即调用Context.lookup,得到DataSource?对象,然后再调用DataSource的getConnection获取数据库连接.
?
?2.在Tommcat 中的Context中配置数据源
?
<Context reloadable="true">
    <Resource name="jdbc/bookstore" auth="Container" type="javax.sql.DataSource"
           maxActive="50" maxIdle="30" maxWait="10000"
           username="pl" password="123"
           driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost:3306/bookstore?autoReconnect=true" />
</Context>
?