It's an example for Java and TiDB. Contains subproject:
We use different frameworks or libraries to implement similar processes to reflect the solution for connecting to TiDB in different environments
This is a process about the game, each player has two attributes,
coins
and goods
, and each player has their own unique id
as an identifier.
Players can trade with each other, provided that the coins
and goods
are sufficient
The process is as follows:
- Create a player
- Create some players
- Read players amount
- Read some players attributes
- Two player trade with insufficient coins or goods
- Two player trade with sufficient coins or goods
It's an example used plain Java and JDBC to connect TiDB.
-
Makefile(recommend)
- Run
make plain-java-jdbc
- Run
-
Manual
- Run create table sql in your TiDB
- Into
plain-java-jdbc
- Run
mvn clean package
- Run
java -jar target/plain-java-jdbc-0.0.1-jar-with-dependencies.jar
plain-java-jdbc expected output
Notes: Hibernate 6.0.0.Beta2 and above supports the TiDB dialect, so our examples will be written based on this version, and we recommend using this version when connecting to TiDB as well
It's an example used plain Java and Hibernate to connect TiDB.
-
Makefile(recommend)
- Run
make plain-java-hibernate
- Run
-
Manual
- Into
plain-java-hibernate
- Run
mvn clean package
- Run
java -jar target/plain-java-hibernate-0.0.1-jar-with-dependencies.jar
- Into
plain-java-hibernate expected output
Notes: Hibernate 6.0.0.Beta2 and above supports the TiDB dialect, so our examples will be written based on this version, and we recommend using this version when connecting to TiDB as well
It's an example service used Spring Boot, JPA and Hibernate to connect TiDB. Provide a group of HTTP Restful interface.
-
Makefile(recommend)
- First terminal
- Run
make spring-jpa-hibernate
- Run
- Second terminal
- Run
make request
- Run
- You can quit first terminal or run
make stop
to stop service
- First terminal
-
Manual
- Into
spring-jpa-hibernate
- Run
mvn clean package
- Run
java -jar target/spring-jpa-hibernate-0.0.1.jar
- Request:
- Option 1 (recommend):
- Input Request Collection to Postman
- Request by Postman application
- Option 2:
- Using script to request. It's based on
curl
- Using script to request. It's based on
- Option 3:
- Request HTTP Restful interface by other way
- Option 1 (recommend):
- Into
- request expected output
- service expected output
- Application Config
- Main Class
- controller (Provide HTTP Restful interface)
- dao (Data access object)
- service (Feature interface and implement)