JDBC Metadata: DatabaseMetaData, ResultSetMetaData and ParameterMetaData
Discover a database's structure and capabilities at run time: DatabaseMetaData for products, features, tables, columns, keys and indexes, ResultSetMetaData for the columns of any query, ParameterMetaData for statement parameters, and the JDBCType enum, with a generic table printer.
kvi5hnuCode Sprout team member8 min readOn this page
Most programs know the tables they work with, because their developers designed them. But some programs must work with any database: SQL consoles, schema browsers, migration and code generation tools, data export utilities, generic admin screens and frameworks such as Hibernate. They need to ask the database what tables exist, what columns those tables have, and what a query will return. Data that describes data is called metadata, and JDBC provides three interfaces for it:
DatabaseMetaData, fromconn.getMetaData(), describes the database: product and driver, supported features and limits, and the schema with its tables, columns, keys, indexes and procedures.ResultSetMetaData, fromrs.getMetaData()or, before executing,preparedStatement.getMetaData(), describes the columns of a query result.ParameterMetaData, frompreparedStatement.getParameterMetaData(), describes a statement's parameters.
DatabaseMetaData: the database itself
DatabaseMetaData has around 180 methods. They fall into a few groups:
- Product and driver:
getDatabaseProductName,getDatabaseProductVersion,getDatabaseMajorVersion,getDriverName,getDriverVersion,getJDBCMajorVersion,getURL,getUserName. - Features: dozens of
supportsXxxmethods:supportsTransactions,supportsSavepoints,supportsBatchUpdates,supportsResultSetType,supportsGetGeneratedKeys,supportsTransactionIsolationLevel, and exotic ones likesupportsCatalogsInPrivilegeDefinitions. AlsogetDefaultTransactionIsolationandgetSQLKeywords(keywords beyond SQL). - Limits:
getMaxConnections,getMaxColumnNameLength,getMaxStatementLengthand similar, where 0 means "no limit or unknown". - Identifier rules:
storesUpperCaseIdentifiers(the standard, used by Oracle, H2 and Db2),storesLowerCaseIdentifiers(PostgreSQL),storesMixedCaseIdentifiers,getIdentifierQuoteString. They matter when you pass names to the methods below. - Supported functions:
getStringFunctions,getNumericFunctions,getTimeDateFunctions,getSystemFunctionslist the JDBC escape functions (article 61) the driver supports.
Schema information as result sets
Methods that describe database objects return their answers as ordinary ResultSets, with columns defined in the DatabaseMetaData Javadoc:
| Method | Describes | Useful columns |
|---|---|---|
getCatalogs(), getSchemas() | catalogs (databases) and schemas | TABLE_CAT, TABLE_SCHEM |
getTables(catalog, schemaPattern, tablePattern, types) | tables, views and others | TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS |
getColumns(catalog, schemaPattern, tablePattern, columnPattern) | columns | COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_SIZE, DECIMAL_DIGITS, IS_NULLABLE, COLUMN_DEF, IS_AUTOINCREMENT |
getPrimaryKeys(catalog, schema, table) | primary key columns | COLUMN_NAME, KEY_SEQ |
getImportedKeys, getExportedKeys | foreign keys from and to a table | FKCOLUMN_NAME, PKTABLE_NAME, PKCOLUMN_NAME |
getIndexInfo(catalog, schema, table, unique, approximate) | indexes | INDEX_NAME, COLUMN_NAME, NON_UNIQUE |
getProcedures, getFunctions, getTypeInfo, getTableTypes | procedures, functions, data types, table kinds |
Arguments ending in "Pattern" accept SQL LIKE patterns (% and _), and null means "don't restrict". Names must be given the way the database stores them: "PRODUCTS" in H2 or Oracle, "products" in PostgreSQL. The types array of getTables filters by kind, such as "TABLE" or "VIEW", and drivers use slightly different names (H2 reports BASE TABLE). getTableTypes() lists them.
ResultSetMetaData: the columns of a result
For any query, ResultSetMetaData tells you:
| Method | Returns |
|---|---|
getColumnCount() | the number of columns |
getColumnLabel(i), getColumnName(i) | the label (the AS alias) and the underlying column name |
getColumnType(i), getColumnTypeName(i) | the type as a java.sql.Types constant and as the database's type name |
getColumnClassName(i) | the Java class getObject returns, such as java.math.BigDecimal |
getPrecision(i), getScale(i), getColumnDisplaySize(i) | sizes |
isNullable(i) | columnNoNulls, columnNullable or columnNullableUnknown |
isAutoIncrement(i), isReadOnly(i), isWritable(i), isSigned(i) | further properties |
getTableName(i), getSchemaName(i) | where the column comes from, empty for computed columns |
preparedStatement.getMetaData() returns the metadata before the query runs, if the driver can determine it. A query tool can then show the columns without fetching data. Some drivers return null here.
Use the label for display and for rs.getXxx(label). The name is the source column, which helps tools that write data back.
JDBCType
getColumnType returns an int from the constants class java.sql.Types. Since Java 8, the enum JDBCType (which implements the interface SQLType) gives the same types names: JDBCType.valueOf(meta.getColumnType(i)) converts the number, and setObject(index, value, JDBCType.DECIMAL) accepts it. Drivers can define their own SQLType implementations for vendor types.
Exploring a schema with H2
This program creates two tables and an index, then reports the product, a few features, the tables, the columns of PRODUCTS, its keys and indexes, and the metadata of a join query and its parameter, all before executing the query:
import java.sql.*;
import java.util.*;
public class Schema {
public static void main(String[] args) throws SQLException {
try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:shop")) {
try (Statement stat = conn.createStatement()) {
stat.executeUpdate("CREATE TABLE suppliers (supplier_id CHAR(4) PRIMARY KEY, name VARCHAR(40) NOT NULL, country VARCHAR(30))");
stat.executeUpdate("""
CREATE TABLE products (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name VARCHAR(60) NOT NULL,
supplier_id CHAR(4) REFERENCES suppliers(supplier_id),
price DECIMAL(8,2) DEFAULT 0,
added DATE)""");
stat.executeUpdate("CREATE INDEX products_by_name ON products(name)");
}
DatabaseMetaData meta = conn.getMetaData();
System.out.println(meta.getDatabaseProductName() + " " + meta.getDatabaseMajorVersion() + "." + meta.getDatabaseMinorVersion()
+ ", user " + meta.getUserName() + ", URL " + meta.getURL());
System.out.println("stores unquoted identifiers in upper case: " + meta.storesUpperCaseIdentifiers()
+ ", quote string: " + meta.getIdentifierQuoteString());
System.out.println("transactions: " + meta.supportsTransactions() + ", savepoints: " + meta.supportsSavepoints()
+ ", batch updates: " + meta.supportsBatchUpdates() + ", default isolation: " + meta.getDefaultTransactionIsolation());
System.out.println("max connections: " + meta.getMaxConnections() + " (0 = no known limit)");
System.out.println("--- tables ---");
try (ResultSet rs = meta.getTables(null, "PUBLIC", "%", new String[] { "TABLE" })) {
while (rs.next()) System.out.println(rs.getString("TABLE_SCHEM") + "." + rs.getString("TABLE_NAME") + " (" + rs.getString("TABLE_TYPE") + ")");
}
System.out.println("--- columns of PRODUCTS ---");
try (ResultSet rs = meta.getColumns(null, "PUBLIC", "PRODUCTS", "%")) {
while (rs.next())
System.out.printf("%-12s %-18s size %-3d nullable %-3s default %-5s autoincrement %s%n",
rs.getString("COLUMN_NAME"), rs.getString("TYPE_NAME"), rs.getInt("COLUMN_SIZE"),
rs.getString("IS_NULLABLE"), rs.getString("COLUMN_DEF"), rs.getString("IS_AUTOINCREMENT"));
}
System.out.println("--- keys and indexes ---");
try (ResultSet rs = meta.getPrimaryKeys(null, "PUBLIC", "PRODUCTS")) {
while (rs.next()) System.out.println("primary key: " + rs.getString("COLUMN_NAME"));
}
try (ResultSet rs = meta.getImportedKeys(null, "PUBLIC", "PRODUCTS")) {
while (rs.next()) System.out.println("foreign key: " + rs.getString("FKCOLUMN_NAME") + " -> "
+ rs.getString("PKTABLE_NAME") + "." + rs.getString("PKCOLUMN_NAME"));
}
try (ResultSet rs = meta.getIndexInfo(null, "PUBLIC", "PRODUCTS", false, false)) {
var indexes = new TreeSet<String>();
while (rs.next()) indexes.add(rs.getString("INDEX_NAME") + " on " + rs.getString("COLUMN_NAME") + (rs.getBoolean("NON_UNIQUE") ? "" : " (unique)"));
indexes.forEach(i -> System.out.println("index: " + i));
}
System.out.println("--- result set metadata ---");
try (PreparedStatement ps = conn.prepareStatement(
"SELECT p.id, p.name AS product, s.name AS supplier, p.price * 1.2 AS gross, p.added FROM products p LEFT JOIN suppliers s ON s.supplier_id = p.supplier_id WHERE p.price > ?")) {
ResultSetMetaData rsmd = ps.getMetaData(); // available before executing
for (int i = 1; i <= rsmd.getColumnCount(); i++)
System.out.printf("%d %-8s name %-5s table %-9s %-17s precision %2d scale %d nullable %d -> %s%n", i,
rsmd.getColumnLabel(i), rsmd.getColumnName(i), rsmd.getTableName(i), rsmd.getColumnTypeName(i),
rsmd.getPrecision(i), rsmd.getScale(i), rsmd.isNullable(i), rsmd.getColumnClassName(i));
ParameterMetaData pmd = ps.getParameterMetaData();
System.out.println("parameter 1: " + pmd.getParameterTypeName(1) + ", mode IN: " + (pmd.getParameterMode(1) == ParameterMetaData.parameterModeIn));
}
}
}
}
Output with H2 2.3:
H2 2.3, user , URL jdbc:h2:mem:shop
stores unquoted identifiers in upper case: true, quote string: "
transactions: true, savepoints: true, batch updates: true, default isolation: 2
max connections: 0 (0 = no known limit)
--- tables ---
PUBLIC.PRODUCTS (BASE TABLE)
PUBLIC.SUPPLIERS (BASE TABLE)
--- columns of PRODUCTS ---
ID INTEGER size 32 nullable NO default null autoincrement YES
NAME CHARACTER VARYING size 60 nullable NO default null autoincrement NO
SUPPLIER_ID CHARACTER size 4 nullable YES default null autoincrement NO
PRICE DECIMAL size 8 nullable YES default 0 autoincrement NO
ADDED DATE size 10 nullable YES default null autoincrement NO
--- keys and indexes ---
primary key: ID
foreign key: SUPPLIER_ID -> SUPPLIERS.SUPPLIER_ID
index: CONSTRAINT_INDEX_F on SUPPLIER_ID
index: PRIMARY_KEY_F on ID (unique)
index: PRODUCTS_BY_NAME on NAME
--- result set metadata ---
1 ID name ID table PRODUCTS INTEGER precision 32 scale 0 nullable 0 -> java.lang.Integer
2 PRODUCT name NAME table PRODUCTS CHARACTER VARYING precision 60 scale 0 nullable 0 -> java.lang.String
3 SUPPLIER name NAME table SUPPLIERS CHARACTER VARYING precision 40 scale 0 nullable 0 -> java.lang.String
4 GROSS name GROSS table NUMERIC precision 10 scale 3 nullable 2 -> java.math.BigDecimal
5 ADDED name ADDED table PRODUCTS DATE precision 10 scale 0 nullable 1 -> java.sql.Date
parameter 1: DECIMAL, mode IN: true
A few observations:
- The default isolation level 2 is
Connection.TRANSACTION_READ_COMMITTED(article 65). - H2 created indexes for the primary key and the foreign key automatically. Their names are generated.
- For the computed
GROSScolumn, the table name is empty and nullability is unknown (2). SUPPLIERis reported ascolumnNoNulls(0) because the column isNOT NULLin its table, although theLEFT JOINcan produce NULLs. Metadata is the driver's best effort, not a guarantee.
The program
The runnable demo builds a result set whose column metadata it defines itself, as a driver would after a query, using RowSetMetaDataImpl and a CachedRowSet. It describes each column from the metadata. A generic printTable method then prints the rows as a text table. It knows nothing about the query: it takes labels, widths and alignment from ResultSetMetaData, right-aligning numeric types identified with JDBCType. Such a method works for any query in any database. Finally, the demo converts some type numbers with JDBCType.
import java.math.BigDecimal;
import java.sql.*;
import java.time.LocalDate;
import java.util.*;
import javax.sql.RowSetMetaData;
import javax.sql.rowset.*;
public class Solution {
// Prints any result set as a text table, using only its metadata: no knowledge of the query
static void printTable(ResultSet rs) throws SQLException {
ResultSetMetaData meta = rs.getMetaData();
int n = meta.getColumnCount();
String[] labels = new String[n];
boolean[] rightAlign = new boolean[n];
int[] widths = new int[n];
for (int i = 0; i < n; i++) {
labels[i] = meta.getColumnLabel(i + 1);
JDBCType type = JDBCType.valueOf(meta.getColumnType(i + 1));
rightAlign[i] = switch (type) {
case TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL, NUMERIC, REAL, FLOAT, DOUBLE -> true;
default -> false;
};
widths[i] = labels[i].length();
}
List<String[]> rows = new ArrayList<>();
rs.beforeFirst();
while (rs.next()) {
String[] row = new String[n];
for (int i = 0; i < n; i++) {
Object value = rs.getObject(i + 1);
row[i] = value == null ? "NULL" : value.toString();
widths[i] = Math.max(widths[i], row[i].length());
}
rows.add(row);
}
StringBuilder line = new StringBuilder("+");
for (int w : widths) line.append("-".repeat(w + 2)).append('+');
System.out.println(line);
System.out.println(format(labels, widths, new boolean[n]));
System.out.println(line);
for (String[] row : rows) System.out.println(format(row, widths, rightAlign));
System.out.println(line);
System.out.println(rows.size() + " row(s)");
}
static String format(String[] cells, int[] widths, boolean[] right) {
var sb = new StringBuilder("|");
for (int i = 0; i < cells.length; i++) {
String fmt = right[i] ? " %" + widths[i] + "s |" : " %-" + widths[i] + "s |";
sb.append(String.format(fmt, cells[i]));
}
return sb.toString();
}
public static void main(String[] args) throws SQLException {
// A result set whose metadata we define ourselves, as a driver would after a query
CachedRowSet rs = RowSetProvider.newFactory().createCachedRowSet();
RowSetMetaData meta = new RowSetMetaDataImpl();
meta.setColumnCount(4);
Object[][] columns = {
{ "ID", Types.INTEGER, "INTEGER", 10, 0, ResultSetMetaData.columnNoNulls, true },
{ "PRODUCT", Types.VARCHAR, "VARCHAR", 60, 0, ResultSetMetaData.columnNoNulls, false },
{ "PRICE", Types.DECIMAL, "DECIMAL", 8, 2, ResultSetMetaData.columnNullable, false },
{ "ADDED", Types.DATE, "DATE", 10, 0, ResultSetMetaData.columnNullable, false } };
for (int i = 0; i < columns.length; i++) {
Object[] c = columns[i];
meta.setColumnName(i + 1, (String) c[0]);
meta.setColumnLabel(i + 1, (String) c[0]);
meta.setColumnType(i + 1, (Integer) c[1]);
meta.setColumnTypeName(i + 1, (String) c[2]);
meta.setPrecision(i + 1, (Integer) c[3]);
meta.setScale(i + 1, (Integer) c[4]);
meta.setNullable(i + 1, (Integer) c[5]);
meta.setAutoIncrement(i + 1, (Boolean) c[6]);
meta.setTableName(i + 1, "PRODUCTS");
}
rs.setMetaData(meta);
Object[][] data = {
{ 1, "Hammer", new BigDecimal("12.50"), java.sql.Date.valueOf(LocalDate.of(2026, 3, 1)) },
{ 2, "Oak shelf", new BigDecimal("89.90"), java.sql.Date.valueOf(LocalDate.of(2026, 5, 17)) },
{ 13, "Gift card", null, null } };
for (Object[] row : data) {
rs.moveToInsertRow();
for (int i = 0; i < row.length; i++) {
if (row[i] == null) rs.updateNull(i + 1); else rs.updateObject(i + 1, row[i]);
}
rs.insertRow();
}
rs.moveToCurrentRow();
System.out.println("--- describing the columns ---");
ResultSetMetaData md = rs.getMetaData();
for (int i = 1; i <= md.getColumnCount(); i++) {
String nullable = switch (md.isNullable(i)) {
case ResultSetMetaData.columnNoNulls -> "NOT NULL";
case ResultSetMetaData.columnNullable -> "NULL";
default -> "unknown";
};
String size = md.getScale(i) > 0 ? "(" + md.getPrecision(i) + "," + md.getScale(i) + ")"
: md.getColumnType(i) == Types.VARCHAR ? "(" + md.getPrecision(i) + ")" : "";
System.out.printf("%-8s %s%s %s%s, JDBCType.%s%n", md.getColumnLabel(i), md.getColumnTypeName(i), size, nullable,
md.isAutoIncrement(i) ? " auto-increment" : "", JDBCType.valueOf(md.getColumnType(i)).getName());
}
System.out.println("--- a generic table printer ---");
printTable(rs);
System.out.println("--- JDBCType and Types ---");
for (JDBCType t : List.of(JDBCType.VARCHAR, JDBCType.DECIMAL, JDBCType.TIMESTAMP_WITH_TIMEZONE, JDBCType.BOOLEAN))
System.out.println(t.getName() + " = Types constant " + t.getVendorTypeNumber() + " (vendor " + t.getVendor() + ")");
try {
JDBCType.valueOf(12345);
} catch (IllegalArgumentException e) {
System.out.println("unknown type number: " + e.getClass().getSimpleName());
}
}
}
--- describing the columns ---
ID INTEGER NOT NULL auto-increment, JDBCType.INTEGER
PRODUCT VARCHAR(60) NOT NULL, JDBCType.VARCHAR
PRICE DECIMAL(8,2) NULL, JDBCType.DECIMAL
ADDED DATE NULL, JDBCType.DATE
--- a generic table printer ---
+----+-----------+-------+------------+
| ID | PRODUCT | PRICE | ADDED |
+----+-----------+-------+------------+
| 1 | Hammer | 12.50 | 2026-03-01 |
| 2 | Oak shelf | 89.90 | 2026-05-17 |
| 13 | Gift card | NULL | NULL |
+----+-----------+-------+------------+
3 row(s)
--- JDBCType and Types ---
VARCHAR = Types constant 12 (vendor java.sql)
DECIMAL = Types constant 3 (vendor java.sql)
TIMESTAMP_WITH_TIMEZONE = Types constant 2014 (vendor java.sql)
BOOLEAN = Types constant 16 (vendor java.sql)
unknown type number: IllegalArgumentException
Common questions
How do I list all tables in the current schema?
meta.getTables(conn.getCatalog(), conn.getSchema(), "%", new String[] {"TABLE"}), and read the TABLE_NAME column. Check getTableTypes() for the exact type names your driver uses (H2 reports BASE TABLE).
Why does getColumns(null, null, "products", null) return nothing?
The database stores unquoted names in another case. Use "PRODUCTS" for H2 and Oracle, "products" for PostgreSQL, or ask meta.storesUpperCaseIdentifiers() and convert accordingly.
What's the difference between getColumnName and getColumnLabel?
The label is the AS alias if there is one, otherwise the name. Display and look up by label; the name refers to the underlying table column, where the driver knows it.
Is metadata access slow?
DatabaseMetaData queries the database's system catalogs, so each call may be a round trip, and some are expensive on large schemas. Cache results in tools that call them repeatedly. ResultSetMetaData is usually free, since it comes with the result.
How do I find out the database version?
meta.getDatabaseProductName() and getDatabaseProductVersion(), or the numeric getDatabaseMajorVersion() and getDatabaseMinorVersion(). getDriverVersion() reports the driver's own version, which is often what matters for bugs and features.
API reference
| API | Purpose |
|---|---|
Connection.getMetaData() | the DatabaseMetaData |
getDatabaseProductName, getDatabaseProductVersion, getDriverName, getDriverVersion, getJDBCMajorVersion | product and driver |
supportsXxx, getDefaultTransactionIsolation, getMaxXxx, getSQLKeywords | features and limits |
storesUpperCaseIdentifiers, storesLowerCaseIdentifiers, getIdentifierQuoteString | identifier rules |
getTables, getColumns, getPrimaryKeys, getImportedKeys, getExportedKeys, getIndexInfo, getProcedures, getTypeInfo | schema information as result sets |
ResultSet.getMetaData(), PreparedStatement.getMetaData() | ResultSetMetaData |
getColumnCount, getColumnLabel, getColumnName, getColumnType, getColumnTypeName, getColumnClassName | column identity and type |
getPrecision, getScale, getColumnDisplaySize, isNullable, isAutoIncrement, getTableName | column details |
PreparedStatement.getParameterMetaData(), getParameterCount, getParameterType, getParameterTypeName, getParameterMode | parameters |
JDBCType.valueOf(int), getVendorTypeNumber, SQLType | type constants as an enum |
Summary
- Metadata describes the database, query results and statement parameters. You need it for tools and frameworks that work with any schema.
DatabaseMetaDatareports the product, the driver, supported features and limits, and returns tables, columns, keys and indexes as result sets. Pass names the way the database stores them.ResultSetMetaDatagives each result column's label, name, type, Java class, size and nullability, which is enough to display any result generically.ParameterMetaDatadescribes the parameters of a prepared statement.JDBCTypeis an enum view of thejava.sql.Typesconstants. Metadata is the driver's best effort, so verify it before relying on details like nullability.
Practice Questions
How do you list all tables (but not views) in the schema PUBLIC?
try (ResultSet rs = conn.getMetaData().getTables(null, "PUBLIC", "%", new String[] { "TABLE" })) { while (rs.next()) ... rs.getString("TABLE_NAME") ... }. The table-type name the driver expects can differ (H2 reports BASE TABLE but accepts "TABLE"). getTableTypes() lists the names it uses.
meta.getColumns(null, null, "products", "%") returns no rows on Oracle, although the table exists. Why?
Oracle stores unquoted identifiers in upper case, so the table is named PRODUCTS in the data dictionary. The metadata methods compare names as stored. Use "PRODUCTS", or check storesUpperCaseIdentifiers() and convert the case. PostgreSQL is the opposite: it stores lower case.
What is the difference between getColumnLabel and getColumnName for SELECT name AS product FROM products?
getColumnLabel returns PRODUCT, the alias from AS, which is what you'd display and pass to rs.getString(label). getColumnName returns NAME, the underlying column. Without an alias, both are the same.
How can a generic export tool decide whether to quote a column's values in a CSV file?
Look at the column type: JDBCType.valueOf(meta.getColumnType(i)). Numeric types (INTEGER, DECIMAL, ...) can be written as they are, while character, date and other types should be quoted and escaped. getColumnClassName(i) gives the Java class as an alternative.
Why might ps.getMetaData() on a prepared statement return null, and what can you do then?
Some drivers can't, or won't, determine a query's result columns without executing it, for example because it would require a server round trip they avoid. The JDBC specification allows returning null. Execute the query and call getMetaData() on the result set instead, perhaps with setMaxRows(1) or a WHERE 1 = 0 condition if you only need the column information.
Previous: JDBC Row Sets: CachedRowSet, WebRowSet, FilteredRowSet and JoinRowSet
Next: JDBC Transactions: Commit, Rollback, Isolation, Save Points and Batch Updates
Related reading
- JDBC Row Sets: CachedRowSet, WebRowSet, FilteredRowSet and JoinRowSet
- Scrollable and Updatable Result Sets in JDBC
- LOBs, SQL Escapes, Multiple Results and Generated Keys in JDBC
- Prepared Statements in JDBC: Parameters, Reuse and Preventing SQL Injection
- Executing SQL with JDBC: Statements, Result Sets and SQL Exceptions

More in Core Java II
FFM Upcalls, Variadic Functions and errno
Advanced FFM calls: passing Java code to C as function pointers with upcall stubs, binding objects and lambdas, calling variadic functions such as printf, capturing errno and GetLastError, and a C library that calls back into Java. The final article of the course.
Calling Foreign Functions: Linker, Symbol Lookup, Downcalls and jextract
Calling C functions from pure Java with the FFM API: the native linker, default, library and loader symbol lookups, function descriptors, downcall handles, invokeExact, pointers and NULL, struct results, critical calls, enabling native access, and generating bindings with jextract.
FFM Memory Layouts: Structs, Unions, Sequences and Var Handles
Describing C data with FFM memory layouts: value layouts and C types, struct and union layouts, alignment and padding, sequences, layout paths, var handles with base offsets, offset and slice handles, pointers with target layouts, and atomic access modes.
Foreign Function and Memory API: Arenas and Memory Segments
Getting started with the FFM API (final since Java 22): a first foreign call, confined, shared, automatic and global arenas, native and heap memory segments, reading and writing values, C strings and arrays, alignment and byte order, slices, copies, allocators, and memory-mapped files.
Discussion
Sign in to ask a question or share what you learned.