doc-exports/docs/dws/dev/dws_04_0083.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

37 lines
5.8 KiB
HTML

<a name="EN-US_TOPIC_0000001233761889"></a><a name="EN-US_TOPIC_0000001233761889"></a>
<h1 class="topictitle1">JDBC Configuration</h1>
<div id="body1528162486098"><p id="EN-US_TOPIC_0000001233761889__p83201518124912">Currently, third-party tools are connected to <span id="EN-US_TOPIC_0000001233761889__text120969138">GaussDB(DWS)</span> trough JDBC. This section describes the precautions for configuring the tools.</p>
<div class="section" id="EN-US_TOPIC_0000001233761889__section51233666102514"><h4 class="sectiontitle">Connection Parameters</h4><ul id="EN-US_TOPIC_0000001233761889__ul4235888102912"><li id="EN-US_TOPIC_0000001233761889__li33742908102912">[Notice] When a third-party tool connects to <span id="EN-US_TOPIC_0000001233761889__text267386391">GaussDB(DWS)</span> through JDBC, JDBC sends a connection request to <span id="EN-US_TOPIC_0000001233761889__text1267787076">GaussDB(DWS)</span>. By default, the following parameters are added. For details, see the implementation of the ConnectionFactoryImpl JDBC code.<pre class="screen" id="EN-US_TOPIC_0000001233761889__screen51783857102912">params = {
{ "user", user },
{ "database", database },
{ "client_encoding", "UTF8" },
{ "DateStyle", "ISO" },
{ "extra_float_digits", "2" },
{ "TimeZone", createPostgresTimeZone() },
};</pre>
<p id="EN-US_TOPIC_0000001233761889__p15181893103553">These parameters may cause the JDBC and gsql clients to display inconsistent data, for example, date data display mode, floating point precision representation, and timezone.</p>
<p id="EN-US_TOPIC_0000001233761889__p63401535102912">If the result is not as expected, you are advised to explicitly set these parameters in the Java connection setting.</p>
</li><li id="EN-US_TOPIC_0000001233761889__li22840275102912">[Proposal] When connecting to the database through JDBC, ensure that the following two time zones are the same:<ul id="EN-US_TOPIC_0000001233761889__ul62190131102912"><li id="EN-US_TOPIC_0000001233761889__li35250721102912">Time zone of the host where the JDBC client is located</li><li id="EN-US_TOPIC_0000001233761889__li16356185655617">Time zone of the host where the <span id="EN-US_TOPIC_0000001233761889__text675913043">GaussDB(DWS)</span> server is located</li></ul>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233761889__section2864318010275"><h4 class="sectiontitle">fetchsize</h4><p id="EN-US_TOPIC_0000001233761889__p1208899">[Notice] To use <strong id="EN-US_TOPIC_0000001233761889__b21951949173115">fetchsize</strong> in applications, disable the <strong id="EN-US_TOPIC_0000001233761889__b842352706145926">autocommit</strong> switch. Enabling the <strong id="EN-US_TOPIC_0000001233761889__b84235270615044">autocommit</strong> switch makes the <strong id="EN-US_TOPIC_0000001233761889__b84235270615111">fetchsize</strong> configuration invalid.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001233761889__section1636443510276"><h4 class="sectiontitle">autocommit</h4><p id="EN-US_TOPIC_0000001233761889__p40373845104858">[Proposal] It is recommended that you enable the <strong id="EN-US_TOPIC_0000001233761889__b842352706142820">autocommit</strong> switch in the code for connecting to <span id="EN-US_TOPIC_0000001233761889__text265447366">GaussDB(DWS)</span> by the JDBC. If <strong id="EN-US_TOPIC_0000001233761889__b842352706143016">autocommit</strong> needs to be disabled to improve performance or for other purposes, applications need to ensure their transactions are committed. For example, explicitly commit translations after specifying service SQL statements. Particularly, ensure that all transactions are committed before the client exits.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001233761889__section1577694110277"><h4 class="sectiontitle">Connection Releasing</h4><p id="EN-US_TOPIC_0000001233761889__p144341064916">[Proposal] You are advised to use connection pools to limit the number of connections from applications. Do not connect to a database every time you run an SQL statement.</p>
<p id="EN-US_TOPIC_0000001233761889__p23100085">[Proposal] After an application completes its tasks, disconnect its connection to <span id="EN-US_TOPIC_0000001233761889__text94760255">GaussDB(DWS)</span> to release occupied resources. You are advised to set the session timeout interval in the task.</p>
<p id="EN-US_TOPIC_0000001233761889__p1964373612402">[Proposal] Reset the session environment before releasing connections to the JDBC connection tool. Otherwise, historical session information may cause object conflicts.</p>
<ul id="EN-US_TOPIC_0000001233761889__ul319815399488"><li id="EN-US_TOPIC_0000001233761889__li319853920486">If GUC parameters are set in the connection, before you return the connection to the connection pool, run <strong id="EN-US_TOPIC_0000001233761889__b155527413207">SET SESSION AUTHORIZATION DEFAULT;RESET ALL;</strong> to clear the connection status.</li><li id="EN-US_TOPIC_0000001233761889__li7553164720488">If a temporary table is used, delete it before you return the connection to the connection pool.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233761889__section1624965810277"><h4 class="sectiontitle">CopyManager</h4><p id="EN-US_TOPIC_0000001233761889__p1841431102854">[Proposal] In the scenario where the ETL tool is not used and real-time data import is required, it is recommended that you use the CopyManager interface driven by the <span id="EN-US_TOPIC_0000001233761889__text12103183452013">GaussDB(DWS)</span> JDBC to import data in batches during application development.</p>
<p id="EN-US_TOPIC_0000001233761889__p17571351132311">For details about how to use CopyManager, see <a href="dws_04_0116.html">CopyManager</a>.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0074.html">Development and Design Proposal</a></div>
</div>
</div>