Package net.risingworld.api.database
Interface Database
- All Superinterfaces:
- AutoCloseable
Database interface which represents a connection to an SQLite or MySQL database.
 
 
Example: Full example of how you may use an SQLite database 
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes this connection.voidExecutes the given SQL statement, for example a CREATE or DELETE statement.executeQuery(String sql) Executes the given SQL statement and returns aResultSetobject.
 Remember to close the ResultSet once you're ready (or use a try-with-resources statement).voidexecuteUpdate(String sql) Executes the given SQL statement, which may be an INSERT, UPDATE or DELETE statement.Gets the underlyingConnectionobject, which represents the connection to the specific database.getType()Gets the database type.
- 
Method Details- 
getTypeDatabaseType getType()Gets the database type.- Returns:
- the database type, SQLite or MySQL
 
- 
getConnectionConnection getConnection()Gets the underlyingConnectionobject, which represents the connection to the specific database. This provides full access to the database. Be careful when changing any settings of this connection;- Returns:
- a Connectionobject.
- Example: Create a PreparedStatement and insert a value in an existing database
 
- 
executeExecutes the given SQL statement, for example a CREATE or DELETE statement.- Parameters:
- sql- the SQL statement.
- Example: Create a custom SQLite connection (creates new database if it does not exist)
 
- 
executeUpdateExecutes the given SQL statement, which may be an INSERT, UPDATE or DELETE statement.- Parameters:
- sql- the SQL statement, INSERT, UPDATE or DELETE.
- Example: Update an entry in an existing database
- Example: Create and insert or update an entry (UPSERT)
 
- 
executeQueryExecutes the given SQL statement and returns aResultSetobject.
 Remember to close the ResultSet once you're ready (or use a try-with-resources statement).- Parameters:
- sql- the SQL statement, typically a SELECT statement.
- Returns:
- a ResultSet object containing the data produced by the given SQL statement.
- Throws:
- SQLException- If a database access error occurs.
- See Also:
 
- 
closevoid close()Closes this connection. Call this method if the connection isn't needed anymore.- Specified by:
- closein interface- AutoCloseable
 
 
-