Files
doc-exports/docs/dli/sqlreference/dli_08_15057.html
Su, Xiaomeng be9eabe464 dli_sqlreference_20250305
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2025-03-25 09:06:21 +00:00

597 lines
50 KiB
HTML

<a name="dli_08_15057"></a><a name="dli_08_15057"></a>
<h1 class="topictitle1">JDBC</h1>
<div id="body0000001784631757"><div class="section" id="dli_08_15057__section11554812174420"><h4 class="sectiontitle">Function</h4><p id="dli_08_15057__dli_08_0270_p7254192618812">The JDBC connector is provided by Apache Flink and can be used to read data from and write data to common databases, such as MySQL and PostgreSQL. Source tables, result tables, and dimension tables are supported.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15057__table3954102713514" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Supported types</caption><thead align="left"><tr id="dli_08_15057__row139551727153515"><th align="left" class="cellrowborder" valign="top" width="33.87%" id="mcps1.3.1.3.2.3.1.1"><p id="dli_08_15057__p169550272355">Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="66.13%" id="mcps1.3.1.3.2.3.1.2"><p id="dli_08_15057__p9955172713520">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_15057__row595518271358"><td class="cellrowborder" valign="top" width="33.87%" headers="mcps1.3.1.3.2.3.1.1 "><p id="dli_08_15057__p4955182716353">Supported Table Types</p>
</td>
<td class="cellrowborder" valign="top" width="66.13%" headers="mcps1.3.1.3.2.3.1.2 "><p id="dli_08_15057__p1595518273356">Source table, dimension table, and result table</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_08_15057__section0641438122515"><h4 class="sectiontitle">Prerequisites</h4><ul id="dli_08_15057__ul036513387289"><li id="dli_08_15057__li036513816282">An enhanced datasource connection with the database has been established, so that you can configure security group rules as required.</li></ul>
</div>
<div class="section" id="dli_08_15057__section15384120152215"><h4 class="sectiontitle">Caveats</h4><ul id="dli_08_15057__ul994995345818"><li id="dli_08_15057__li61591759105810">The JDBC sink operates in upsert mode for exchanging UPDATE/DELETE messages with the external system if a primary key is defined on the DDL, otherwise, it operates in append mode and does not support to consume UPDATE/DELETE messages.</li><li id="dli_08_15057__li13608118132418">When you create a Flink OpenSource SQL job, set <strong id="dli_08_15057__dli_08_15029_b163001353185217">Flink Version</strong> to <strong id="dli_08_15057__dli_08_15029_b1430115539523">1.15</strong> in the <strong id="dli_08_15057__dli_08_15029_b1030175315523">Running Parameters</strong> tab. Select <strong id="dli_08_15057__dli_08_15029_b430135325212">Save Job Log</strong>, and specify the OBS bucket for saving job logs.</li><li id="dli_08_15057__li980192610493">Storing authentication credentials such as usernames and passwords in code or plaintext poses significant security risks. It is recommended using DEW to manage credentials instead. Storing encrypted credentials in configuration files or environment variables and decrypting them when needed ensures security. For details, see .</li></ul>
</div>
<div class="section" id="dli_08_15057__section055264284416"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_08_15057__screen143570576440">create table jbdcTable (
attr_name attr_type
(',' attr_name attr_type)*
(','PRIMARY KEY (attr_name, ...) NOT ENFORCED)
(',' watermark for rowtime_column_name as watermark-strategy_expression)
) with (
'connector' = 'jdbc',
'url' = '',
'table-name' = '',
'username' = '',
'password' = ''
);</pre>
</div>
<div class="section" id="dli_08_15057__section1918619215263"><h4 class="sectiontitle">Description</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15057__table3535131492817" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Parameters</caption><thead align="left"><tr id="dli_08_15057__row053518147287"><th align="left" class="cellrowborder" valign="top" width="22.29%" id="mcps1.3.5.2.2.6.1.1"><p id="dli_08_15057__p153513145285">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="8.55%" id="mcps1.3.5.2.2.6.1.2"><p id="dli_08_15057__p10535014202815">Mandatory</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="7.02%" id="mcps1.3.5.2.2.6.1.3"><p id="dli_08_15057__p519717173594">Default Value</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="8.63%" id="mcps1.3.5.2.2.6.1.4"><p id="dli_08_15057__p41981824182510">Data Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="53.510000000000005%" id="mcps1.3.5.2.2.6.1.5"><p id="dli_08_15057__p19535151482813">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_15057__row653531413287"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p117141241192315">connector</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p81135102314">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p121977179596">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p91981924142514">String</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p1471424117235">Connector to be used. Set this parameter to <strong id="dli_08_15057__b63294111393612">jdbc</strong>.</p>
</td>
</tr>
<tr id="dli_08_15057__row65351614172820"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p15535141432819">url</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p1653517144282">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p91971417175910">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p61987241254">String</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p12535914122818">Database URL</p>
<ul id="dli_08_15057__ul192502021847"><li id="dli_08_15057__li11250421949">To connect to a MySQL database, the format is <strong id="dli_08_15057__b6726121312132">jdbc:mysql://</strong><em id="dli_08_15057__i205989332139">MySQL address</em><strong id="dli_08_15057__b13147175713138">:</strong><em id="dli_08_15057__i1888264613138">MySQL port</em>/<em id="dli_08_15057__i9981159141310">Database name</em>.</li><li id="dli_08_15057__li106756239410">To connect to a PostgreSQL database, the format is <strong id="dli_08_15057__b1412115184148">jdbc:postgresql://</strong><em id="dli_08_15057__i1944771517">PostgreSQL address</em><strong id="dli_08_15057__b2890428141516">:</strong><em id="dli_08_15057__i2052882516158">PostgreSQL port</em><strong id="dli_08_15057__b11614133610152">/</strong><em id="dli_08_15057__i63541033111513">Database name</em>.</li></ul>
</td>
</tr>
<tr id="dli_08_15057__row11535151410283"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p38121811155819">table-name</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p653621414283">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p19197141712593">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p171981424142513">String</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p2536191418289">Name of the table where the data will be read from the database</p>
</td>
</tr>
<tr id="dli_08_15057__row753618145283"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p95361214202815">driver</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p1353613148281">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p56391492212">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p1919816241258">String</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p1453631462817">Driver required for connecting to the database. If you do not set this parameter, the automatically extracted URL will be used.</p>
<ul id="dli_08_15057__ul1325832512916"><li id="dli_08_15057__li1325842511918">The default driver of the MySQL database is <strong id="dli_08_15057__b1391354141513">com.mysql.jdbc.Driver</strong>.</li><li id="dli_08_15057__li7258192520915">The default driver of the PostgreSQL database is <strong id="dli_08_15057__b1943626167">org.postgresql.Driver</strong>.</li></ul>
</td>
</tr>
<tr id="dli_08_15057__row195361114142812"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p105364142285">username</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p1128519229372">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p3197141710593">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p71981424112514">String</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p175361714162814">Database authentication user name. This parameter must be configured in pair with <strong id="dli_08_15057__b77885642493612">password</strong>.</p>
</td>
</tr>
<tr id="dli_08_15057__row553641414283"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p6536614122819">password</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p6536131442814">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p619719176592">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p7198142472520">String</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p953641462814">Database authentication password. This parameter must be configured in pair with <strong id="dli_08_15057__b97037357493612">username</strong>.</p>
</td>
</tr>
<tr id="dli_08_15057__row18832171192112"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p15932155482114">connection.max-retry-timeout</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p2832011172120">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p168321511122110">60s</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p9832111162118">Duration</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p48321811152111">Maximum timeout between retries. The timeout should be in second granularity and should not be smaller than 1 second.</p>
</td>
</tr>
<tr id="dli_08_15057__row19302036122619"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p4302163618260">scan.partition.column</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p2302936102619">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p154557176223">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p1730273617268">String</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p6302103662613">Name of the column used to partition the input. For details, see <a href="#dli_08_15057__section1974210303182">Partitioned Scan</a>.</p>
</td>
</tr>
<tr id="dli_08_15057__row134301838192610"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p843013819269">scan.partition.num</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p04300381265">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p3811191832217">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p16430143819260">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p14301382269">Number of partitions to be created. For details, see <a href="#dli_08_15057__section1974210303182">Partitioned Scan</a>.</p>
</td>
</tr>
<tr id="dli_08_15057__row79030405264"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p1903154032610">scan.partition.lower-bound</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p9903104016266">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p209032404269">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p1790315402265">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p8903174032617">Lower bound of values to be fetched for the first partition. For details, see <a href="#dli_08_15057__section1974210303182">Partitioned Scan</a>.</p>
</td>
</tr>
<tr id="dli_08_15057__row116874711260"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p769184712611">scan.partition.upper-bound</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p3691047182611">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p1469154711263">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p1169174715266">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p1769647142616">Upper bound of values to be fetched for the last partition. For details, see <a href="#dli_08_15057__section1974210303182">Partitioned Scan</a>.</p>
</td>
</tr>
<tr id="dli_08_15057__row8938124482614"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p16938164415261">scan.fetch-size</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p16938844172619">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p1493854482612">0</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p2938194414263">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p20938164416260">Number of rows fetched from the database each time. If this parameter is set to <strong id="dli_08_15057__b163957514593612">0</strong>, the SQL hint is ignored.</p>
</td>
</tr>
<tr id="dli_08_15057__row128981142132615"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p1289874282616">scan.auto-commit</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p78981542132612">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p118981442102613">true</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p12898442132616">Boolean</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p118981642122610">Whether each statement is committed in a transaction automatically.</p>
</td>
</tr>
<tr id="dli_08_15057__row1276405373917"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p176466162401">lookup.cache.max-rows</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p147645533398">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p1576418531395">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p77643536391">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p1076416530392">Maximum number of rows in the lookup cache. When the rows exceed this value, the first item added to the cache will be marked as expired. By default, the lookup cache is not enabled. For details, see <a href="#dli_08_15057__section1425410298425">Lookup Cache Functions</a>.</p>
</td>
</tr>
<tr id="dli_08_15057__row118592056113919"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p118931929154010">lookup.cache.ttl</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p1485985643911">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p12859135653915">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p1086715563393">Duration</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p58673561397">Maximum survival time of each record in the lookup cache. When the rows exceed this value, the first item added to the cache will be marked as expired. By default, the lookup cache is not enabled. For details, see <a href="#dli_08_15057__section1425410298425">Lookup Cache Functions</a>.</p>
</td>
</tr>
<tr id="dli_08_15057__row477617074012"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p16249136154017">lookup.cache.caching-missing-key</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p177614054015">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p1277650114014">true</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p177690184017">Boolean</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p777617013409">Whether to cache empty query results. The default value is <strong id="dli_08_15057__b1247531852312">true</strong>. For details, see <a href="#dli_08_15057__section1425410298425">Lookup Cache Functions</a>.</p>
</td>
</tr>
<tr id="dli_08_15057__row25519419407"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p1261164164014">lookup.max-retries</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p255114424019">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p1655112414019">3</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p6551154184013">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p16551154134016">Maximum number of retry attempts when a database query fails.</p>
</td>
</tr>
<tr id="dli_08_15057__row5976974405"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p153182053124013">sink.buffer-flush.max-rows</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p697615704019">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p99763716402">100</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p1976977402">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p14976187174011">Maximum number of cached records before flushing, which can be set to <strong id="dli_08_15057__b155895071710">0</strong> to disable it.</p>
</td>
</tr>
<tr id="dli_08_15057__row517164644019"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p9881105814408">sink.buffer-flush.interval</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p917115465404">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p917114617405">1s</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p81715469408">Duration</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p15171104694018">The interval for flushing, after which the asynchronous thread will flush the data. Can be set to <strong id="dli_08_15057__b22502861715">0</strong> to disable it. To fully handle the flush events of the cache asynchronously, <strong id="dli_08_15057__b946519105179">sink.buffer-flush.max-rows</strong> can be set to <strong id="dli_08_15057__b446651011715">0</strong> and an appropriate flush time interval can be configured.</p>
</td>
</tr>
<tr id="dli_08_15057__row1050074814404"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p187335884112">sink.max-retries</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p85001148144019">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p75001948174011">3</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p4500748184016">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p7500114824014">Maximum number of retries after a failed attempt to write records to the database.</p>
</td>
</tr>
<tr id="dli_08_15057__row199443419"><td class="cellrowborder" valign="top" width="22.29%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15057__p1065371319418">sink.parallelism</p>
</td>
<td class="cellrowborder" valign="top" width="8.55%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15057__p209647419">No</p>
</td>
<td class="cellrowborder" valign="top" width="7.02%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15057__p993424116">None</p>
</td>
<td class="cellrowborder" valign="top" width="8.63%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15057__p12912411413">Integer</p>
</td>
<td class="cellrowborder" valign="top" width="53.510000000000005%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15057__p799444117">Defines the parallelism of the JDBC sink operator. By default, the parallelism is determined by the framework: using the same parallelism as the upstream chained operator.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_08_15057__section1974210303182"><a name="dli_08_15057__section1974210303182"></a><a name="section1974210303182"></a><h4 class="sectiontitle">Partitioned Scan</h4><p id="dli_08_15057__p199541741131817">To accelerate reading data in parallel Source task instances, Flink provides the partitioned scan feature for the JDBC table. The following parameters describe how to partition the table when reading in parallel from multiple tasks.</p>
<ul id="dli_08_15057__ul1994135133816"><li id="dli_08_15057__li159416354383"><strong id="dli_08_15057__b6298213393612">scan.partition.column</strong>: name of the column used to partition the input. The data type of the column must be number, date, or timestamp.</li><li id="dli_08_15057__li1394135133819"><strong id="dli_08_15057__b103822431293612">scan.partition.num</strong>: number of partitions.</li><li id="dli_08_15057__li1946353389"><strong id="dli_08_15057__b138589750893612">scan.partition.lower-bound</strong>: minimum value of the first partition.</li><li id="dli_08_15057__li12946354389"><strong id="dli_08_15057__b20998807393612">scan.partition.upper-bound</strong>: maximum value of the last partition.</li></ul>
<div class="note" id="dli_08_15057__note0764113618395"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="dli_08_15057__ul12418539392"><li id="dli_08_15057__li18249530391"><strong id="dli_08_15057__b790811474192">When a table is created, the preceding partitioned scan parameters must all be specified if any of them is specified.</strong></li><li id="dli_08_15057__li4365165410396">The <strong id="dli_08_15057__b211258484793613">scan.partition.lower-bound</strong> and <strong id="dli_08_15057__b142324185593613">scan.partition.upper-bound</strong> parameters are used to decide the partition stride instead of filtering rows in the table. All rows in the table are partitioned and returned.</li></ul>
</div></div>
</div>
<div class="section" id="dli_08_15057__section1425410298425"><a name="dli_08_15057__section1425410298425"></a><a name="section1425410298425"></a><h4 class="sectiontitle">Lookup Cache Functions</h4><p id="dli_08_15057__p189048104524">The JDBC connector can be used as a lookup dimension table in temporal table joins, and currently only supports synchronous lookup mode.</p>
<p id="dli_08_15057__p16887181015612">By default, lookup cache is disabled. Therefore, all requests are sent to the external database. You can set <strong id="dli_08_15057__b24753452201">lookup.cache.max-rows</strong> and <strong id="dli_08_15057__b2475114513208">lookup.cache.ttl</strong> to enable this feature. The main purpose of the lookup cache is to improve the performance of the JDBC connector in temporal table joins.</p>
<p id="dli_08_15057__p1090411015520">When the lookup cache is enabled, each process (i.e. TaskManager) will maintain a cache. Flink will first look up the cache, and only when the cache is not found will it send a request to the external database and update the cache with the returned data. When the cache hits the maximum cache rows <strong id="dli_08_15057__b1851711422210">lookup.cache.max-rows</strong> or when the rows exceed the maximum survival time <strong id="dli_08_15057__b175178427220">lookup.cache.ttl</strong>, the first item added to the cache will be marked as expired. The records in the cache may not be the latest, and users can set <strong id="dli_08_15057__b146911926201917">lookup.cache.ttl</strong> to a smaller value to get better data refresh, but this may increase the number of requests sent to the database. Therefore, a balance between throughput and correctness should be maintained.</p>
<p id="dli_08_15057__p119041910115216">By default, Flink caches empty query results for primary keys, but you can switch this behavior by setting <strong id="dli_08_15057__b74801249192017">lookup.cache.caching-missing-key</strong> to <strong id="dli_08_15057__b10480184932015">false</strong>.</p>
</div>
<div class="section" id="dli_08_15057__section167782952515"><h4 class="sectiontitle">Data Type Mapping</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15057__table1763835011280" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Data type mapping</caption><thead align="left"><tr id="dli_08_15057__row1638125032818"><th align="left" class="cellrowborder" valign="top" width="27.339999999999996%" id="mcps1.3.8.2.2.4.1.1"><p id="dli_08_15057__p2063895012811">MySQL Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="20.25%" id="mcps1.3.8.2.2.4.1.2"><p id="dli_08_15057__p192231755102915">PostgreSQL Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="52.410000000000004%" id="mcps1.3.8.2.2.4.1.3"><p id="dli_08_15057__p963855013286">Flink SQL Type</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_15057__row156381350142816"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p31591335132718">TINYINT</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p18223175514292">-</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p1563885082814">TINYINT</p>
</td>
</tr>
<tr id="dli_08_15057__row363865082813"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p1562412015278">SMALLINT</p>
<p id="dli_08_15057__p1562440162719">TINYINT UNSIGNED</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p8362313123110">SMALLINT</p>
<p id="dli_08_15057__p3641315173118">INT2</p>
<p id="dli_08_15057__p113023181317">SMALLSERIAL</p>
<p id="dli_08_15057__p1522395514291">SERIAL2</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p6638105011280">SMALLINT</p>
</td>
</tr>
<tr id="dli_08_15057__row11638125012281"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p953995032711">INT</p>
<p id="dli_08_15057__p428445819276">MEDIUMINT</p>
<p id="dli_08_15057__p6638950112817">SMALLINT UNSIGNED</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p184911541319">INTEGER</p>
<p id="dli_08_15057__p6223155512291">SERIAL</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p2063818509282">INT</p>
</td>
</tr>
<tr id="dli_08_15057__row13638450112816"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p1729512711282">BIGINT</p>
<p id="dli_08_15057__p206381450112812">INT UNSIGNED</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p1828235614304">BIGINT</p>
<p id="dli_08_15057__p11223175532910">BIGSERIAL</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p1263865022815">BIGINT</p>
</td>
</tr>
<tr id="dli_08_15057__row13638250192812"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p15638115052818">BIGINT UNSIGNED</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p222315558298">-</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p263825032811">DECIMAL(20, 0)</p>
</td>
</tr>
<tr id="dli_08_15057__row2063845012816"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p9638750182819">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p6223115519291">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p2638135012812">BIGINT</p>
</td>
</tr>
<tr id="dli_08_15057__row20638195018282"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p1163835062813">FLOAT</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p189716430307">REAL</p>
<p id="dli_08_15057__p6223195512919">FLOAT4</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p116388508284">FLOAT</p>
</td>
</tr>
<tr id="dli_08_15057__row1063805022817"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p123932031102812">DOUBLE</p>
<p id="dli_08_15057__p2638105062810">DOUBLE PRECISION</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p1773253420308">FLOAT8</p>
<p id="dli_08_15057__p1022320555298">DOUBLE PRECISION</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p6638185017285">DOUBLE</p>
</td>
</tr>
<tr id="dli_08_15057__row66381502282"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p169583762812">NUMERIC(p, s)</p>
<p id="dli_08_15057__p14638165042819">DECIMAL(p, s)</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p378392733020">NUMERIC(p, s)</p>
<p id="dli_08_15057__p722355562911">DECIMAL(p, s)</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p2638205072819">DECIMAL(p, s)</p>
</td>
</tr>
<tr id="dli_08_15057__row16638650192819"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p2413502283">BOOLEAN</p>
<p id="dli_08_15057__p1663875011285">TINYINT(1)</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p622365520291">BOOLEAN</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p1263835016287">BOOLEAN</p>
</td>
</tr>
<tr id="dli_08_15057__row46385509281"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p1463845017289">DATE</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p9223055192918">DATE</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p3638145012818">DATE</p>
</td>
</tr>
<tr id="dli_08_15057__row106381950122815"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p12638165018287">TIME [(p)]</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p102232556296">TIME [(p)] [WITHOUT TIMEZONE]</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p1863875042813">TIME [(p)] [WITHOUT TIMEZONE]</p>
</td>
</tr>
<tr id="dli_08_15057__row1363825082820"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p196381950182814">DATETIME [(p)]</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p622312554298">TIMESTAMP [(p)] [WITHOUT TIMEZONE]</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p5638350132818">TIMESTAMP [(p)] [WITHOUT TIMEZONE]</p>
</td>
</tr>
<tr id="dli_08_15057__row4638175032820"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p182297293">CHAR(n)</p>
<p id="dli_08_15057__p16753613202914">VARCHAR(n)</p>
<p id="dli_08_15057__p16638850182817">TEXT</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p69611143172914">CHAR(n)</p>
<p id="dli_08_15057__p197622463293">CHARACTER(n)</p>
<p id="dli_08_15057__p782394862919">VARCHAR(n)</p>
<p id="dli_08_15057__p1266195692910">CHARACTER</p>
<p id="dli_08_15057__p174231553192914">VARYING(n)</p>
<p id="dli_08_15057__p0223555152916">TEXT</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p6638195019280">STRING</p>
</td>
</tr>
<tr id="dli_08_15057__row663845017282"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p10502721132918">BINARY</p>
<p id="dli_08_15057__p15293925132912">VARBINARY</p>
<p id="dli_08_15057__p12638150192818">BLOB</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p922325542917">BYTEA</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p96382503282">BYTES</p>
</td>
</tr>
<tr id="dli_08_15057__row16638450142813"><td class="cellrowborder" valign="top" width="27.339999999999996%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dli_08_15057__p1638185042816">-</p>
</td>
<td class="cellrowborder" valign="top" width="20.25%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dli_08_15057__p1322316556293">ARRAY</p>
</td>
<td class="cellrowborder" valign="top" width="52.410000000000004%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dli_08_15057__p1463805022811">ARRAY</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_08_15057__section163901016188"><h4 class="sectiontitle">Example</h4><ul id="dli_08_15057__ul1852074213433"><li id="dli_08_15057__li105201442184311"><strong id="dli_08_15057__b1921131373319">Example 1: Use JDBC as the data source and Print as the result table to read data from an RDS MySQL database and write it into the Print result table.</strong><ol id="dli_08_15057__ol165798537434"><li id="dli_08_15057__li3579453164319">Create an enhanced datasource connection in the VPC and subnet where RDS MySQL locates, and bind the connection to the required Flink elastic resource pool.</li><li id="dli_08_15057__li20462193104410">Set RDS MySQL security groups and add inbound rules to allow access from the Flink queue. Test the connectivity using the RDS address. If the connection passes the test, it is bound to the queue.</li><li id="dli_08_15057__li7651143404412">Log in to the RDS MySQL database, create table <strong id="dli_08_15057__b2749013093613">orders</strong> in the Flink database, and insert data. <p id="dli_08_15057__p18651153418447">Create table <strong id="dli_08_15057__b163090110993613">orders</strong> in the Flink database.</p>
<pre class="screen" id="dli_08_15057__screen12906191404716">CREATE TABLE `flink`.`orders` (
`order_id` VARCHAR(32) NOT NULL,
`order_channel` VARCHAR(32) NULL,
PRIMARY KEY (`order_id`)
) ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_general_ci;</pre>
<p id="dli_08_15057__p10980104513449">Insert data into the table.</p>
<pre class="screen" id="dli_08_15057__screen29651938174717">insert into orders(
order_id,
order_channel
) values
('1', 'webShop'),
('2', 'miniAppShop');</pre>
</li><li id="dli_08_15057__li55041921154813">Create a Flink OpenSource SQL job. Enter the following job script and submit the job.<p id="dli_08_15057__p7531144416281"><a name="dli_08_15057__li55041921154813"></a><a name="li55041921154813"></a>When you create a job, set <strong id="dli_08_15057__b130482057122729">Flink Version</strong> to <strong id="dli_08_15057__b32725076122729">1.15</strong> in the <strong id="dli_08_15057__b90805163122729">Running Parameters</strong> tab. Select <strong id="dli_08_15057__b153372121022729">Save Job Log</strong>, and specify the OBS bucket for saving job logs. <strong id="dli_08_15057__b12663145201710">Change the values of the parameters in bold as needed in the following script.</strong></p>
<p id="dli_08_15057__p165461254155220">Storing authentication credentials such as usernames and passwords in code or plaintext poses significant security risks. It is recommended using DEW to manage credentials instead. Storing encrypted credentials in configuration files or environment variables and decrypting them when needed ensures security. For details, see .</p>
<pre class="screen" id="dli_08_15057__screen557462565218">CREATE TABLE jdbcSource (
order_id string,
order_channel string
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:mysql://<em id="dli_08_15057__i130275669193613"><strong id="dli_08_15057__b118065294293613">MySQLAddress</strong></em>:<em id="dli_08_15057__i197546665093613"><strong id="dli_08_15057__b113309673793613">MySQLPort</strong></em>/<strong id="dli_08_15057__b103567331893613"><em id="dli_08_15057__i3282533893613">flink</em></strong>',--flink is the database name created in RDS MySQL.
'table-name' = 'orders',
'username' = '<em id="dli_08_15057__i179068635319"><strong id="dli_08_15057__b1090616617531">MySQL</strong></em><em id="dli_08_15057__i290616145316"><strong id="dli_08_15057__b199069611534">Username</strong></em>',
'password' = '<em id="dli_08_15057__i790618617534"><strong id="dli_08_15057__b1790611685312">MySQL</strong></em><em id="dli_08_15057__i18906963533"><strong id="dli_08_15057__b19906663537">Password</strong></em>',
'scan.fetch-size' = '10',
'scan.auto-commit' = 'true'
);
CREATE TABLE printSink (
order_id string,
order_channel string
) WITH (
'connector' = 'print'
);
insert into printSink select * from jdbcSource;</pre>
</li><li id="dli_08_15057__li1426213282537">View the data result in the <strong id="dli_08_15057__b79541137285">taskmanager.out</strong> file. The data result is as follows:<pre class="screen" id="dli_08_15057__screen82675845312">+I(1,webShop)
+I(2,miniAppShop)</pre>
</li></ol>
</li><li id="dli_08_15057__li16279736135413"><strong id="dli_08_15057__b6708185053119">Example 2: Send data using the DataGen source table and output data to a MySQL database through the JDBC result table.</strong><ol id="dli_08_15057__ol894812711118"><li id="dli_08_15057__li182761736131719">Create an enhanced datasource connection in the VPC and subnet where RDS MySQL locates, and bind the connection to the required Flink elastic resource pool.</li><li id="dli_08_15057__li1827633615172">Set RDS MySQL security groups and add inbound rules to allow access from the Flink queue. Test the connectivity using the RDS address. If the connection passes the test, it is bound to the queue.</li><li id="dli_08_15057__li1427633612173">Log in to the RDS MySQL database, create table <strong id="dli_08_15057__b26598190393613">orders</strong> in the Flink database, and insert data. <div class="p" id="dli_08_15057__p1327603618173">Create table <strong id="dli_08_15057__b138564246893613">orders</strong> in the Flink database.<pre class="screen" id="dli_08_15057__screen143891493123">CREATE TABLE `flink`.`orders` (
`order_id` VARCHAR(32) NOT NULL,
`order_channel` VARCHAR(32) NULL,
PRIMARY KEY (`order_id`)
) ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_general_ci;</pre>
</div>
</li><li id="dli_08_15057__li12772614175712">Create a Flink OpenSource SQL job. Enter the following job script and submit the job.<p id="dli_08_15057__p15755539288"><a name="dli_08_15057__li12772614175712"></a><a name="li12772614175712"></a>When you create a job, set <strong id="dli_08_15057__b1499747056">Flink Version</strong> to <strong id="dli_08_15057__b2034158524">1.15</strong> in the <strong id="dli_08_15057__b591751781">Running Parameters</strong> tab. Select <strong id="dli_08_15057__b381751530">Save Job Log</strong>, and specify the OBS bucket for saving job logs. <strong id="dli_08_15057__b133414048191124">Change the values of the parameters in bold as needed in the following script.</strong></p>
<pre class="screen" id="dli_08_15057__screen1248215762318">CREATE TABLE dataGenSource (
order_id string,
order_channel string
) WITH (
'connector' = 'datagen',
'fields.order_id.kind' = 'sequence',
'fields.order_id.start' = '1',
'fields.order_id.end' = '1000',
'fields.order_channel.kind' = 'random',
'fields.order_channel.length' = '5'
);
CREATE TABLE jdbcSink (
order_id string,
order_channel string,
PRIMARY KEY(order_id) NOT ENFORCED
) WITH (
'connector' = 'jdbc',
'url? = 'jdbc:mysql://<em id="dli_08_15057__i62491333793613"><strong id="dli_08_15057__b210157984893613">MySQLAddress:MySQLPort</strong></em>/flink',-- flink is the MySQL database where the <strong id="dli_08_15057__b186894946993613">orders</strong> table locates.
'table-name' = 'orders',
'username' = '<em id="dli_08_15057__i914912159593"><strong id="dli_08_15057__b3149131585919">MySQL</strong></em><em id="dli_08_15057__i19846218135920"><strong id="dli_08_15057__b12575101815911">Username</strong></em>',
'password' = '<em id="dli_08_15057__i42321325155913"><strong id="dli_08_15057__b202321525105915">MySQL</strong></em><em id="dli_08_15057__i4741529185918"><strong id="dli_08_15057__b874482815599">Password</strong></em>',
'sink.buffer-flush.max-rows' = '1'
);
insert into jdbcSink select * from dataGenSource;</pre>
</li><li id="dli_08_15057__li126645549401">Run the SQL statement in the MySQL database to view data in the table:<pre class="screen" id="dli_08_15057__screen16682191234213">select * from orders;</pre>
</li></ol>
</li><li id="dli_08_15057__li64365568549"><strong id="dli_08_15057__b189731841173210">Example 3: Read data from the DataGen source table, use the JDBC table as the dimension table, and write the table information generated by both into the Print result table.</strong><ol id="dli_08_15057__ol10688125519438"><li id="dli_08_15057__li10396103116158">Create an enhanced datasource connection in the VPC and subnet where RDS MySQL locates, and bind the connection to the required Flink elastic resource pool.</li><li id="dli_08_15057__li73961231111519">Set RDS MySQL security groups and add inbound rules to allow access from the Flink queue. Test the connectivity using the RDS address. If the connection passes the test, it is bound to the queue.</li><li id="dli_08_15057__li6396153181518">Log in to the RDS MySQL database, create table <strong id="dli_08_15057__b153451221993613">orders</strong> in the Flink database, and insert data. <p id="dli_08_15057__p839612317155">Create table <strong id="dli_08_15057__b121206428593613">orders</strong> in the Flink database.</p>
<pre class="screen" id="dli_08_15057__screen17396143112157">CREATE TABLE `flink`.`orders` (
`order_id` VARCHAR(32) NOT NULL,
`order_channel` VARCHAR(32) NULL,
PRIMARY KEY (`order_id`)
) ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_general_ci;</pre>
<p id="dli_08_15057__p939710315150">Insert data into the table.</p>
<pre class="screen" id="dli_08_15057__screen0397173121514">insert into orders(
order_id,
order_channel
) values
('1', 'webShop'),
('2', 'miniAppShop');</pre>
</li><li id="dli_08_15057__li252222512418">Create a Flink OpenSource SQL job. Enter the following job script and submit the job. This job script uses DataGen as the data source and JDBC as the dimension table to write data into the Print result table.<p id="dli_08_15057__p310342142915"><a name="dli_08_15057__li252222512418"></a><a name="li252222512418"></a>When you create a job, set <strong id="dli_08_15057__b122417217322729">Flink Version</strong> to <strong id="dli_08_15057__b57044129022729">1.15</strong> in the <strong id="dli_08_15057__b125590627422729">Running Parameters</strong> tab. Select <strong id="dli_08_15057__b37633355822729">Save Job Log</strong>, and specify the OBS bucket for saving job logs. <strong id="dli_08_15057__b109744070">Change the values of the parameters in bold as needed in the following script.</strong></p>
<pre class="screen" id="dli_08_15057__screen19218815104718">CREATE TABLE dataGenSource (
order_id string,
order_time timestamp,
proctime as Proctime()
) WITH (
'connector' = 'datagen',
'fields.order_id.kind' = 'sequence',
'fields.order_id.start' = '1',
'fields.order_id.end' = '2'
);
--Creating a dimension table
CREATE TABLE jdbcTable (
order_id string,
order_channel string
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:mysql:/<em id="dli_08_15057__i8576204362912">/JDBC address</em>:<em id="dli_08_15057__i1220834722919">JDBC port</em>/flink',--flink is the name of the database where the <strong id="dli_08_15057__b49121574302">orders</strong> table of RDS for MySQL is located.
'table-name' = 'orders',
'username' = '<em id="dli_08_15057__i6295142115419"><strong id="dli_08_15057__b152956215546">JDBC</strong></em><em id="dli_08_15057__i112957235411"><strong id="dli_08_15057__b929532125417">UserName</strong></em>',
'password' = '<em id="dli_08_15057__i6988101115511"><strong id="dli_08_15057__b149881811105518">JDBCPassWord'</strong></em>,
'lookup.cache.max-rows' = '100',
'lookup.cache.ttl' = '1000',
'lookup.cache.caching-missing-key' = 'false',
'lookup.max-retries' = '5'
);
CREATE TABLE printSink (
order_id string,
order_time timestamp,
order_channel string
) WITH (
'connector' = 'print'
);
insert into
printSink
SELECT
dataGenSource.order_id, dataGenSource.order_time, jdbcTable.order_channel
from
dataGenSource
left join jdbcTable for system_time as of dataGenSource.proctime on dataGenSource.order_id = jdbcTable.order_id;</pre>
</li><li id="dli_08_15057__li798764924410">View the data result in the <strong id="dli_08_15057__b107555142304">taskmanager.out</strong> file. The data result is as follows:<pre class="screen" id="dli_08_15057__screen18988154914446">+I(1, xxx, webShop)
+I(2, xxx, miniAppShop)</pre>
</li></ol>
</li></ul>
</div>
<div class="section" id="dli_08_15057__section35840248116"><h4 class="sectiontitle">FAQ</h4><p id="dli_08_15057__p9265163315399">None</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_15027.html">Connectors</a></div>
</div>
</div>