uTools-Manuals/docs/java/javax/sql/DataSource.html

170 lines
8.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="header">
<div class="subTitle">
compact2, compact3
</div>
<div class="subTitle">
javax.sql
</div>
<h2 class="title" title="Interface DataSource">Interface DataSource</h2>
</div><div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>
All Superinterfaces:
</dt>
<dd>
<span><a href="../../javax/sql/CommonDataSource.html" title="javax.sql中的接口">CommonDataSource</a> <a href="../../java/sql/Wrapper.html" title="java.sql中的接口">Wrapper</a></span>
</dd>
</dl>
<hr/> <br/> <pre>public interface <span class="typeNameLabel">DataSource</span>
extends <a href="../../javax/sql/CommonDataSource.html" title="interface in javax.sql">CommonDataSource</a>, <a href="../../java/sql/Wrapper.html" title="interface in java.sql">Wrapper</a></pre>
<div class="block">
<p> <span>一个连接到这个<code>DataSource</code>对象所代表的物理数据源的工厂。</span> <span><code>DriverManager</code>设备的<code>DriverManager</code> <code>DataSource</code>对象是获取连接的首选方法。</span> <span>实现<code>DataSource</code>接口的对象通常将基于Java“命名和目录JNDIAPI”的命名服务注册。</span> </p>
<p> <span><code>DataSource</code>接口由驱动程序供应商实现。</span> <span>有三种类型的实现:</span> </p>
<ol>
<li> <span>基本实现 - 生成标准的<code>Connection</code>对象</span> </li>
<li> <span>连接池实现 - 生成将自动参与连接池的<code>Connection</code>对象。</span> <span>此实现与中间层连接池管理器配合使用。</span> </li>
<li> <span>分布式事务实现 - 生成可用于分布式事务的<code>Connection</code>对象,并且几乎总是参与连接池。</span> <span>此实现与中间层事务管理器一起工作,并且几乎总是使用连接池管理器。</span> </li>
</ol>
<p> <span>一个<code>DataSource</code>对象具有必要时可以修改的属性。</span> <span>例如,如果将数据源移动到其他服务器,则可以更改服务器的属性。</span> <span>好处是因为可以更改数据源的属性,所以不需要更改访问该数据源的任何代码。</span> </p>
<p> <span>经由一个访问的驱动器<code>DataSource</code>对象不与寄存器本身<code>DriverManager</code></span> <span>相反, <code>DataSource</code>对象虽然查找操作检索,然后用于创建<code>Connection</code>对象。</span> <span>通过基本实现,通过<code>DataSource</code>对象获得的连接与通过<code>DriverManager</code>工具获得的连接<code>DriverManager</code></span> </p>
<p> <span>DataSource的<code>DataSource</code>必须包括一个public no-arg构造函数。</span> </p>
</div>
<dl>
<dt>
<span class="simpleTagLabel">从以下版本开始:</span>
</dt>
<dd>
1.4
</dd>
</dl> </li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- --> </a> <h3>方法摘要</h3>
<table border="0" cellpadding="3" cellspacing="0" class="memberSummary" summary="Method Summary table, listing methods, and an explanation">
<caption>
<span class="activeTableTab" id="t0"><span>所有方法</span><span class="tabEnd"> </span></span>
<span class="tableTab" id="t2"><span><a href="javascript:show(2);">接口方法</a></span><span class="tabEnd"> </span></span>
<span class="tableTab" id="t3"><span><a href="javascript:show(4);">抽象方法</a></span><span class="tabEnd"> </span></span>
</caption>
<tbody>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor" id="i0">
<td class="colFirst"><code><a href="../../java/sql/Connection.html" title="interface in java.sql">Connection</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/sql/DataSource.html#getConnection--">getConnection</a></span>()</code>
<div class="block">
尝试建立与此
<code>DataSource</code>对象所代表的数据源的连接。
</div> </td>
</tr>
<tr class="rowColor" id="i1">
<td class="colFirst"><code><a href="../../java/sql/Connection.html" title="interface in java.sql">Connection</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/sql/DataSource.html#getConnection-java.lang.String-java.lang.String-">getConnection</a></span>(<a href="../../java/lang/String.html" title="class in java.lang">String</a> username, <a href="../../java/lang/String.html" title="class in java.lang">String</a> password)</code>
<div class="block">
尝试建立与该
<code>DataSource</code>对象所代表的数据源的连接。
</div> </td>
</tr>
</tbody>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.javax.sql.CommonDataSource">
<!-- --> </a> <h3>Methods inherited from interface javax.sql.<a href="../../javax/sql/CommonDataSource.html" title="interface in javax.sql">CommonDataSource</a></h3> <code><a href="../../javax/sql/CommonDataSource.html#getLoginTimeout--">getLoginTimeout</a>, <a href="../../javax/sql/CommonDataSource.html#getLogWriter--">getLogWriter</a>, <a href="../../javax/sql/CommonDataSource.html#getParentLogger--">getParentLogger</a>, <a href="../../javax/sql/CommonDataSource.html#setLoginTimeout-int-">setLoginTimeout</a>, <a href="../../javax/sql/CommonDataSource.html#setLogWriter-java.io.PrintWriter-">setLogWriter</a></code></li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.sql.Wrapper">
<!-- --> </a> <h3>Methods inherited from interface java.sql.<a href="../../java/sql/Wrapper.html" title="interface in java.sql">Wrapper</a></h3> <code><a href="../../java/sql/Wrapper.html#isWrapperFor-java.lang.Class-">isWrapperFor</a>, <a href="../../java/sql/Wrapper.html#unwrap-java.lang.Class-">unwrap</a></code></li>
</ul> </li>
</ul> </li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- --> </a> <h3>方法详细信息</h3> <a name="getConnection--">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>getConnection</h4> <pre><a href="../../java/sql/Connection.html" title="interface in java.sql">Connection</a> getConnection()
throws <a href="../../java/sql/SQLException.html" title="class in java.sql">SQLException</a></pre>
<div class="block">
<p>尝试建立与此<code>DataSource</code>对象所代表的数据源的连接。 </p>
</div>
<dl>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
与数据源的连接
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/sql/SQLException.html" title="class in java.sql">SQLException</a></code> - 如果发生数据库访问错误
</dd>
<dd>
<code><a href="../../java/sql/SQLTimeoutException.html" title="class in java.sql">SQLTimeoutException</a></code> - 当驱动程序确定已经超过
<code>setLoginTimeout</code>方法指定的超时值并且至少尝试取消当前数据库连接尝试
</dd>
</dl> </li>
</ul> <a name="getConnection-java.lang.String-java.lang.String-">
<!-- --> </a>
<ul class="blockListLast">
<li class="blockList"> <h4>getConnection</h4> <pre><a href="../../java/sql/Connection.html" title="interface in java.sql">Connection</a> getConnection(<a href="../../java/lang/String.html" title="class in java.lang">String</a> username,
<a href="../../java/lang/String.html" title="class in java.lang">String</a> password)
throws <a href="../../java/sql/SQLException.html" title="class in java.sql">SQLException</a></pre>
<div class="block">
<p>尝试建立与此<code>DataSource</code>对象所代表的数据源的连接。 </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<code>username</code> - 正在连接的数据库用户
</dd>
<dd>
<code>password</code> - 用户密码
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
与数据源的连接
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/sql/SQLException.html" title="class in java.sql">SQLException</a></code> - 如果发生数据库访问错误
</dd>
<dd>
<code><a href="../../java/sql/SQLTimeoutException.html" title="class in java.sql">SQLTimeoutException</a></code> - 当驱动程序确定已经超过
<code>setLoginTimeout</code>方法指定的超时值并且至少尝试取消当前数据库连接尝试
</dd>
<dt>
<span class="simpleTagLabel">从以下版本开始:</span>
</dt>
<dd>
1.4
</dd>
</dl> </li>
</ul> </li>
</ul> </li>
</ul>
</div>
</div>