import java.sql.*;
public class TransactionExample {
public static void main(String[] args) throws SQLException {
String driverClassName = "org.apache.jena.jdbc.tdb.TDBDriver";
String connectionUrl = "jdbc:jena:tdb:directory=/path/to/tdb:namespace=http://example.com";
String username = "your-username";
String password = "your-password";
Class.forName(driverClassName);
Connection connection = DriverManager.getConnection(connectionUrl, username, password);
try {
connection.setAutoCommit(false);
String insertQuery = "INSERT INTO mydata (subject, predicate, object) VALUES (?, ?, ?)";
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, "http://example.com/subject");
preparedStatement.setString(2, "http://example.com/predicate");
preparedStatement.setString(3, "http://example.com/object");
preparedStatement.executeUpdate();
connection.commit();
} catch (SQLException e) {
connection.rollback();
e.printStackTrace();
} finally {
connection.close();
}
}
}