With the classes ObjectLoader and the HSRecordSet SQL commands can be executed.
A HSRecordSet object is used to read data from a database.
The HSRecordSet object has several getObject()
methods, which return a specified object. Use one the methods.
Example:
try { // Getting the connection ConnectionDescriptor des = ObjectLoader.getConnectionDescriptor( "tables/example.connection"); String sql = "SELECT lastname FROM KUNDEN"; // Send the SQL statement HSRecordSet hsRecordSet = new HSRecordSet(sql, des); // The results number of rows int rowCount = hsRecordSet.getRowCount(); // Outputting the result for (int i = 0; i < rowCount; i++) { hsRecordSet.absolute(i + 1); String name = (String) hsRecordSet.getObject( "lastname"); System.out.println(i + ":" + name); } } catch (Exception e) { e.printStackTrace(); }
Objects of the class QueryDescriptor used to
execute sql statements in a database. The method getQueryDescriptor(String sqlStatement, boolean update)
returns a QueryDescriptor.
The attibute "sqlStatement" is the statement to execute.
The attribute "update" must be true. After this call the method executeUpdate(queryDescriptor) of the class DBUtils.
Beispiel:
try { QueryDescriptor queryDescriptor = DBUtils. getQueryDescriptor("DELETE FROM Kunden Where ID = 234", true); DBUtils.executeUpdate(queryDescriptor); } catch (Exception e) { e.printStackTrace(); }