Package net.risingworld.api.database
Schnittstelle Database
- Alle Superschnittstellen:
AutoCloseable
Database interface which represents a connection to an SQLite or MySQL database.
Example: Full example of how you may use an SQLite database
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
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.
-
Methodendetails
-
getType
DatabaseType getType()Gets the database type.- Gibt zurück:
- 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;- Gibt zurück:
- a
Connection
object. - Example: Create a PreparedStatement and insert a value in an existing database
-
execute
Executes the given SQL statement, for example a CREATE or DELETE statement.- Parameter:
sql
- the SQL statement.- Example: Create a custom SQLite connection (creates new database if it does not exist)
-
executeUpdate
Executes the given SQL statement, which may be an INSERT, UPDATE or DELETE statement.- Parameter:
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)
-
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).- Parameter:
sql
- the SQL statement, typically a SELECT statement.- Gibt zurück:
- a ResultSet object containing the data produced by the given SQL statement.
- Löst aus:
SQLException
- If a database access error occurs.- Siehe auch:
-
close
void close()Closes this connection. Call this method if the connection isn't needed anymore.- Angegeben von:
close
in SchnittstelleAutoCloseable
-