Help Center/ MapReduce Service/ Developer Guide (LTS)/ Doris Development Guide (Security Mode)/ Doris Application Development/ Doris JDBC API Invoking Sample Program/ Querying Doris Table Data
Updated on 2026-06-29 GMT+08:00
Querying Doris Table Data
This section describes the sample code for querying Doris table data.
The following code snippet is in the JDBCExample class.
Use Java JDBC to run SQL statements to query data in the dbName.tableName table in the cluster.
String querySql = "select * from " + dbName + "." + tableName + " limit 10";
private static void query(Connection connection, String sql) throws Exception {
try (Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery(sql)) {
ResultSetMetaData md = resultSet.getMetaData();
int columnCount = md.getColumnCount();
StringBuffer stringBuffer = new StringBuffer();
logger.info("Start to print query result.");
for (int i = 1; i <= columnCount; i++) {
stringBuffer.append(md.getColumnName(i));
stringBuffer.append(" ");
}
logger.info(stringBuffer.toString());
while (resultSet.next()) {
stringBuffer = new StringBuffer();
for (int i = 1; i <= columnCount; i++) {
stringBuffer.append(resultSet.getObject(i));
stringBuffer.append(" ");
}
logger.info(stringBuffer.toString());
}
} catch (Exception e) {
logger.error("Execute sql {} failed.", sql, e);
throw new Exception(e);
}
} Parent topic: Doris JDBC API Invoking Sample Program
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot