📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

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

TiDB Cloud LakeJavaNotes
Integers
TINYINTByte
SMALLINTShort
INTInteger
BIGINTLong
TINYINT UNSIGNEDShort
SMALLINT UNSIGNEDInteger
INT UNSIGNEDLong
BIGINT UNSIGNEDBigInteger
Floating Point
FLOATFloat
DOUBLEDouble
DECIMALBigDecimalPrecision preserved
Other Types
BOOLEANBoolean
STRINGString
DATEDate
TIMESTAMPTimestamp
ARRAY(T)StringJSON encoded
TUPLE(...)StringJSON encoded
MAP(K,V)StringJSON encoded
VARIANTStringJSON encoded
BITMAPStringBase64 encoded

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

Was this page helpful?