-
Notifications
You must be signed in to change notification settings - Fork 0
Native query
Eduardo William Karpinski Priester edited this page Oct 1, 2021
·
1 revision
public static void main(String[] args) {
// execute but no return
HCFConnection.sendSQL("DELETE FROM myentity WHERE id = 1");
// executes returning the fields in object array
List<?> recordsInElements = HCFConnection.getElementsBySQL("SELECT * FROM myentity WHERE id = 1");
for (Object record : recordsInElements) {
Object[] columns = (Object[]) record;
System.out.println(columns[0]); // id
System.out.println(columns[1]); // text
}
// or
recordsInElements.stream()
.map(record -> (Object[]) record)
.map(array -> new MyEntity(Long.valueOf(array[0].toString()), array[1].toString()))
.forEach(System.out::println);
// execute by returning the entity (must use *)
List<MyEntity> records = new HCFConnection<>(MyEntity.class).getObjectBySQL("SELECT * FROM myentity WHERE id = 1");
records.forEach(System.out::println);
}