Updated on 2026-06-29 GMT+08:00

Inserting Data into a Doris Table

This section describes the sample code for inserting data into a Doris table.

The following code snippet is in the JDBCExample class.

Run the following SQL statement in Java JDBC mode to insert data into the dbName.tableName table of the cluster.

String insertTableSql = "insert into " + dbName + "." + tableName + " values(?, ?, ?)";
private static void insert(Connection connection, String sql) throws Exception {
   int INSERT_BATCH_SIZE = 10;
   try(PreparedStatement stmt = connection.prepareStatement(sql)) {
      for (int i =0; i < INSERT_BATCH_SIZE; i++) {
         stmt.setInt(1, i);
         stmt.setInt(2, i * 10);
         stmt.setString(3, String.valueOf(i * 100));
         stmt.addBatch();
      }
      stmt.executeBatch();
   } catch (Exception e) {
      logger.error("Execute sql {} failed.", sql, e);
      throw new Exception(e);
   }
}