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 Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this connection.void
Executes the given SQL statement, for example a CREATE or DELETE statement.executeQuery
(String sql) Executes the given SQL statement and returns aResultSet
object.
Remember to close the ResultSet once you're ready (or use a try-with-resources statement).void
executeUpdate
(String sql) Executes the given SQL statement, which may be an INSERT, UPDATE or DELETE statement.Gets the underlyingConnection
object, which represents the connection to the specific database.getType()
Gets the database type.
-
Method Details
-
getType
DatabaseType getType()Gets the database type.- Returns:
- the database type, SQLite or MySQL
-
getConnection
Connection getConnection()Gets the underlyingConnection
object, 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
Connection
object.
-
execute
Executes the given SQL statement, for example a CREATE or DELETE statement.- Parameters:
sql
- the SQL statement.
-
executeUpdate
Executes the given SQL statement, which may be an INSERT, UPDATE or DELETE statement.- Parameters:
sql
- the SQL statement, INSERT, UPDATE or DELETE.
-
executeQuery
Executes the given SQL statement and returns aResultSet
object.
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:
-
close
void close()Closes this connection. Call this method if the connection isn't needed anymore.- Specified by:
close
in interfaceAutoCloseable
-