当前位置:网站首页>[in depth understanding of tcaplus DB technology] Introduction to tcaplus JDBC development
[in depth understanding of tcaplus DB technology] Introduction to tcaplus JDBC development
2022-06-22 20:02:00 【InfoQ】
【 In depth understanding of TcaplusDB technology 】 introduction Tcaplus-JDBC Development
TcaplusDB-JDBC summary
TcaplusDB-JDBC and Java Version compatibility
- **JDBC edition :**TcaplusDB JDBC Realized JDBC 11.1.0, And compatible with later versions .
- **TcaplusDB edition :**TcaplusDB-JDBC be based on TcaplusDB 3.53.0 Development .
- **Java edition :**TcaplusDB-JDBC be based on java1.8 Development .
- Compile required JDK: compile TcaplusDB-JDBC need JDK8.0 Or later .
TcaplusDB-JDBC Quick start
jdbc:tcaplusdb://<instance_ip>:<instance_port>?app_id=<app_id>&zone_id=<zone_id>
import java.sql.*;public class ConnTest { final public static void main(String[] args) { String url = "jdbc:tcaplusdb://192.168.0.1:9999?app_id=2&zone_id=3"; Properties connProperties = new Properties(); connProperties.setProperty("app_password", "123456");//set password try { final Connection connection = DriverManager.getConnection(url,connProperties); try { final Statement statement = connection.createStatement(); try { final String SQL = "SELECT * FROM \"user\" WHERE user_id = '10000'"; final ResultSet resultSet = statement.executeQuery(SQL); try { while (resultSet.next()) { System.out.println(resultSet.getString(1)); } } finally { resultSet.close(); } } finally { statement.close(); } } finally { connection.close(); } } catch (Exception e) { e.printStackTrace(); System.out.println("Test failed"); } }}
TcaplusDB-JDBC Installation
Download and install
# Deploy to /root/tcaplusdb-jdbcmkdir /root/tcaplusdb-jdbccd /root/tcaplusdb-jdbc# download wget https://tcaplus-demo-1301716906.cos.ap-guangzhou.myqcloud.com/TcaplusJDBC3.53.1.204689.x86_64_release_20210802.tar.gz# decompression tar -zxvf TcaplusJDBC3.53.1.204689.x86_64_release_20210802.tar.gz
To configure CLASSPATH
tcaplus-jdbc-[version].jarCLASSPATH-cpCLASSPATH# Bourne-compatible shell (sh, ksh, bash, zsh):shell> export CLASSPATH=/path/tcaplus-jdbc-[version].jar:$CLASSPATH# C shell (csh, tcsh):shell> setenv CLASSPATH /path/tcaplus-jdbc-[version].jar:$CLASSPATH
CLASSPATH.profile.login/etc/profileTcaplusDB-JDBC Example
Example table definition
<?xml version="1.0" encoding="GBK" standalone="yes" ?><metalib name="demo_table" tagsetversion="1" version="1"> <struct name="user" version="1" primarykey="user_id,server_id" splittablekey="user_id"> <entry name="user_id" type="string" size="450" desc=" user ID"/> <entry name="server_id" type="uint64" desc=" The server ID" /> <entry name="nick_name" type="string" size="50" desc=" nickname "/> <entry name="desc" type="string" size="1024" desc=" Description information "/> <entry name="state" type="Tinyuint" defaultvalue="0" desc=" User state 0 : AVALIABLE, 1 DELETED"/> <index name="index1" column="user_id"/> <index name="index2" column="user_id,server_id"/> </struct></metalib>
- Elements metalib yes xml The root element of the file .
- contain primarykey Of struct Element is a table , It doesn't contain primarykey Of struct The element is an ordinary structure .
- Every time the table structure is modified , The version attribute value needs to be added accordingly 1, The initial version is always 1.
- primarykey Property specifies the primary key field ; about generic surface , You can specify at most 8 Primary key fields , about list surface , You can specify 7 individual .
- splittablekey Property is equivalent to a partition key (shard key),TcaplusDB Tables are split and stored to multiple storage nodes .splittablekey Must be one of the primary key fields , A good splittablekey It should be highly decentralized , This means a wide range of values , String type is recommended .
- desc Property contains the description of the current element .
- entry Element defines a field , Supported value types include int32,string,char,int64,double,short etc. .
- index Element defines an index , The index must contain splittablekey. Because you can use the primary key to query the table , Therefore, the index should not be the same as the primary key attribute .
Sample table creation
# step0, Download table definition file . stay Chrome Browser access :https://tcaplus-demo-1301716906.cos.ap-guangzhou.myqcloud.com/table-define.xml Right click the web page , Save as file .# step1, Use Chrome browser , Sign in web View console , Open the browser , Input web Address :[cvm Extranet ip]:80, Account passwords are tcaplus. Open... In the menu bar : The business management =〉 Watch management .# step2, page Tab Column , Choose : Table to add # step3, Select the business and cluster and check the game area , colony :test_set(1), Business :tdr_app(2), Game Zone ID: 3, Click again : Batch add table # step4, In the page that comes out , Browse to the bottom of the page , Click on : Add... From local file , Select the sample table definition file downloaded from the above resources in the pop-up page :table-define.xml# step5, Click on : Submit , establish 3 A sample table : user, server, mail# step6, Check whether the table is created ok, Get into : The business management => Watch management , Select the corresponding business (tdr_app) And the game area (3), See if user, server, mail Table information
Get the connection
DriverManagermain()CLASSPATHDriverManagerDriverManager.getConnection()ConnectionDriverManagerConnectiongetConnection()// take app_password Pass in Properties object Connection conn = null;String url="jdbc:tcaplusdb://192.168.0.1:9999?app_id=2&zone_id=3";Properties connectProperties = new Properties();connectProperties.setProperty("app_password", "123456");try { conn = DriverManager.getConnection(url,connectProperties);} catch (SQLException e) {}
// stay url It is specified in app_passwordConnection conn = null;String url="jdbc:tcaplusdb://192.168.0.1:9999?app_id=2&zone_id=3&app_password='123456'";try { conn = DriverManager.getConnection(url);} catch (SQLException e) {}
ConnectionStatementPreparedStatementperform sql
StatementResultSetDriverManager.getConnection()ConnectioncreateStatement()StatementexecuteQuery(String)executeUpdate(String SQL)execute(String SQL)truefalsegetResultSet()StatementgetUpdateCount()import java.sql.*;public class Demo{ public static void main(String[] args){ Connection connection = null; String url="jdbc:tcaplusdb://192.168.0.1:9999?app_id=2&zone_id=3"; Properties connectProperties = new Properties(); connectProperties.setProperty("app_password", "123456"); try { connection = DriverManager.getConnection(connectURL, connectProperties); Statement statement = connection.createStatement(); try { String SQL = "SELECT * FROM \"user\" WHERE user_id='10000';"; ResultSet resultSet = statement.executeQuery(SQL); try { printResultSet(resultSet); } finally { resultSet.close(); } } finally { statement.close(); } } finally { connection.close(); } }}
TcaplusDB-JDBC Reference resources
The driver / Data source class name
java.sql.Drivercom.tencent.tcaplusdb.DriverConnect URL grammar
jdbc:tcaplusdb://<instance_ip>:<instance_port>?app_id=<app_id>&zone_id=<zone_id>&app_password=<app_password>
- <instance_ip> For instance host ip;
- <instance_port> Open port ;
- <app_id> For the business id;
- <zone_id> For the game area id;
- <app_password> For business password ;
jdbc:tcaplusdb://127.0.0.1:9999?app_id=2&zone_id=3&app_password="123456"jdbc:tcaplusdb://<instance_ip>:<instance_port>?app_id=<app_id>&zone_id=<zone_id>
API Implementation notes
- BLOB
- Use the search method (
getBytes()( wait ) stay BLOB On the data stream .
- For columns with distributed indexes created , You can use column aliases , The value of this column is the same as BLOB The actual name of the is the same , for example :
SELECT id, "data" from table_name
DatabaseMetaData.locatorsUpdateCopies()PreparedStatement.setBlob()- Connect
isClosed()No way ping Server to determine if it is available . according to jdbc standard , Only inclosed()It returns after being called by the connection true.
- Database metadata
- It can be done by
getTable(),getColumn()Fetch metadata
- PreparedStatement
- Be careful when using precompiled statements on the server side
setBlob(). To re execute a statement that changes any large parameter to a non large parameter , Please callclearParameters()And set all parameters again . Here's why :
- During server-side prepared statements and client-side simulation , Only in
PreparedStatement.execute()Big data will be exchanged only when called .
- Once that is done , The stream used to read client data will be closed ( according to JDBC standard ), And cannot be read again .
- ResultSet
- By default ,ResultSets Will be completely retrieved and stored in memory , If you use stream results , If you want to maintain concurrent access to the tables referenced by the statements that generate the result set , Please deal with them as soon as possible .
data type
java.lang.StringCharacter set
Error code
TcaplusDB-JDBC High availability
TcaplusDB-JDBC Known problems and SQL limitations
SQL The limitation of grammar
The insert
INSERT INTO demo (key1,key2,key3,value1,value2) VALUES (x1,x2,x3,x4,x5);
INSERT INTO demo (key1,key2,key3,value1,value2) VALUES (x1,x2,x3,x4,x5); INSERT INTO demo (key1,key2,key3,value1,value2) VALUES (x6,x7,x8,x9,x10);
where Clause syntax restrictions
WHERE key1=x1 AND key2=x2 AND key3=x3;
WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
WHERE key1=x1 AND key2=x2;
WHERE key1=x1 AND key2=x2 AND ( Filter conditions );
Delete operation
DELETE FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3;DELETE FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
DELETE FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 OR key1=x4 AND key2=x5 AND key3=x6;DELETE FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3; DELETE FROM demo WHERE key1=x4 AND key2=x5 AND key3=x6;
update operation
UPDATE demo SET value1=x1, value2=x2 WHERE key1=x1 AND key2=x2 AND key3=x3;UPDATE demo SET value1=x1, value2=x2 WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
UPDATE demo SET value1=x1, value2=x2 WHERE key1=x3 AND key2=x4 AND key3=x5 OR key1=x8 AND key2=x9 AND key3=x10;UPDATE demo SET value1=x1, value2=x2 WHERE key1=x3 AND key2=x4 AND key3=x5; UPDATE demo SET value1=x6, value2=x7 WHERE key1=x8 AND key2=x9 AND key3=x10;
Query operation
SELECT * FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3;SELECT * FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3;SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
SELECT * FROM demo WHERE key1=x1 AND key2=x2;SELECT * FROM demo WHERE key1=x1 AND key2=x2 AND ( Filter conditions );SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2;SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2 AND ( Filter conditions );
SELECT * FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 OR key1=x4 AND key2=x5 AND key3=x6;
SELECT * FROM demo WHERE key1=x1 AND key2=x2 OR key1=x3 AND key2=x4;
Global index query
Supported by sql Query statement
Conditions of the query
SELECT * FROM `mail` WHERE user_id>="10004" AND server_id=100;SELECT * FROM `mail` WHERE user_id BETWEEN 10000 AND 10003 AND server_id=100;SELECT * FROM `mail` WHERE user_id="10000" AND server_id=100 AND mail_id LIKE "210507%";SELECT * FROM `mail` WHERE user_id>="10004" OR server_id<=200;
Paging query
SELECT * FROM mail WHERE user_id>"10000" LIMIT 100 OFFSET 2;
Aggregate query
SELECT server_id, COUNT(DISTINCT user_id), COUNT(*), SUM(state) FROM `mail` WHERE user_id>="10000" AND server_id=100;
Partial field query
SELECT user_id, `subject` FROM mail WHERE user_id>="10000";
Don't support sql Query statement
Mixing aggregate queries with non aggregate queries is not supported
I won't support it order by Inquire about
I won't support it group by Inquire about
I won't support it having Inquire about
Multi table joint query is not supported
Nesting... Is not supported select Inquire about
Other queries not supported
TcaplusDB-JDBC Transaction support

边栏推荐
- Goldfish rhca memoirs: do447 managing user and team access -- creating and managing ansible tower users
- 从11小时到25秒--还有优化空间吗?
- 【深入理解TcaplusDB技术】TcaplusDB 表管理——新建表
- 【小资说库】掰扯下概念:数据、数据库、数据库系统、数据库管理系统、数据库技术
- 漫话Redis源码之一百二十二
- Fault analysis | from data_ Free exception
- iVX无代码挑战五秒游戏制作
- How to use yincan IS903 to master DIY's own USB flash disk? (good items for practicing BGA welding)
- AB打包有的Shader没有触发IPreprocessShaders的回调
- undefined reference 之坑
猜你喜欢

Damp 3D printer consumables

2. what is mechanical design?

请你描述下从浏览器上输入一个url到呈现出页面的整个过程。

Tree, forest and transformation of binary tree

Recommend an anatomy website

程序员应该怎么查日期

Some problem records of openpnp using process

图的存储结构(邻接矩阵)

Search, insert and delete of binary sort tree

Openpnp debugging ------ 0816 Feida Tui 0402 taping
随机推荐
Concordia University | volume product cycle network for reward generation in reinforcement learning
图的定义及术语
Goldfish rhca memoirs: do447 managing user and team access -- creating and managing ansible tower users
插值查找和折半(二分)查找
【深入理解TcaplusDB技术】TcaplusDB运维单据
Definitions and terms of drawings
Some problem records of openpnp using process
关键路径
0.1----- process of drawing PCB with AD
Huffman tree (C language)
Fault analysis | from data_ Free exception
[in depth understanding of tcapulusdb technology] new models of tcapulusdb
Damp 3D printer consumables
Traversal of trees and forests
Modify the antd tree component so that its subclasses are arranged horizontally.
【深入理解TcaplusDB技术】如何启动TcaplusDB进程
Download files through Base64 (convert Base64 to BLOB)
0816 shortcomings of Feida (improvement direction)
University of Calgary | recommendation system based on Reinforcement Learning
[deeply understand tcapulusdb technology] how to initialize and launch tcapulusdb machine