Connect to TiDB Cloud Lake Using Java
The official JDBC driver provides standard JDBC 4.0 compatibility for seamless integration with Java applications.
Installation
Maven
<dependency>
<groupId>com.tidbcloud</groupId>
<artifactId>lake-jdbc</artifactId>
<version>0.4.6</version>
</dependency>
Gradle
implementation 'com.tidbcloud:lake-jdbc:0.4.6'
Connection String: See drivers overview for DSN format and examples.
Key Features
- ✅ JDBC 4.0 Compatible: Standard JDBC interface support
- ✅ Connection Pooling: Built-in connection management
- ✅ Prepared Statements: Efficient parameterized queries
- ✅ Batch Operations: Bulk insert and update supportations
Data Type Mappings
Basic Usage
import java.sql.*;
// Connect to TiDB Cloud Lake
Connection conn = DriverManager.getConnection("<your-dsn>");
// DDL: Create table
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE users (id INT, name STRING, email STRING)");
// Write: Insert data
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO users VALUES (?, ?, ?)");
pstmt.setInt(1, 1);
pstmt.setString(2, "Alice");
pstmt.setString(3, "alice@example.com");
int result = pstmt.executeUpdate();
// Write: Insert data with executeBatch
pstmt = conn.prepareStatement("INSERT INTO users VALUES (?, ?, ?)");
pstmt.setInt(1, 2);
pstmt.setString(2, "Bob");
pstmt.setString(3, "Bob@example.com");
pstmt.addBatch();
pstmt.setInt(1, 3);
pstmt.setString(2, "John");
pstmt.setString(3, "John@example.com");
pstmt.addBatch();
int[] results = pstmt.executeBatch();
// Query: Select data
ResultSet rs = stmt.executeQuery("SELECT id, name, email FROM users WHERE id = 1");
while (rs.next()) {
System.out.println("User: " + rs.getInt("id") + ", " +
rs.getString("name") + ", " +
rs.getString("email"));
}
// Close connections
rs.close();
stmt.close();
pstmt.close();
conn.close();
Configuration Reference
For complete lake-jdbc driver configuration options including:
- Connection string parameters
- SSL/TLS configuration
- Authentication methods
- Performance tuning parameters
Please refer to the official lake-jdbc Connection Guide.
Resources
- Maven Central: lake-jdbc
- GitHub Repository: lake-jdbc
- JDBC Documentation: Oracle JDBC Guide