Package ece.ing3.java.projet.database
Class Database
java.lang.Object
ece.ing3.java.projet.database.Database
Database helper.
Offers utility functions to manage a database. Database configuration is loaded automatically.
- Author:
- Virgile, Nicolas, Louis-Félix
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose()Closes the database.static voidconnect()Connects to the database.static ResultSetExecute a SQL query on the database.static voidFill the database with example data.static Connectionget()Gets the current connection.static DataSourceGets the data source.static StringGets the embedded user database JDBC URL.static voidinit()Initialize the database with required schema.static PreparedStatementpreparedStatement(String query) Create a new prepared statement on the opened database, using the provided SQL query.static StatementCreate a new statement on the opened database.static booleanvalidate()Validates the database's schema schema.
-
Constructor Details
-
Database
public Database()
-
-
Method Details
-
connect
Connects to the database.- Throws:
DatabaseException- Database errorConfigurationException- Invalid configuration
-
validate
Validates the database's schema schema.- Returns:
trueif the schema is correct- Throws:
DatabaseException
-
init
Initialize the database with required schema.- Throws:
DatabaseException- Database error
-
fillWithExamples
Fill the database with example data.- Throws:
DatabaseException- Database error
-
getDataSource
Gets the data source.- Returns:
- Data source
-
get
Gets the current connection.- Returns:
- Connection
-
statement
Create a new statement on the opened database.- Returns:
- Created blank statement
- Throws:
DatabaseException- Database error
-
preparedStatement
Create a new prepared statement on the opened database, using the provided SQL query.- Parameters:
query- SQL query- Returns:
- Prepared statement
- Throws:
DatabaseException- Database error
-
execute
Execute a SQL query on the database.- Parameters:
query- SQL query to execute- Returns:
- Query result
- Throws:
DatabaseException- Database error
-
close
Closes the database.- Throws:
DatabaseException- Database error
-
getEmbeddedUserDatabaseUrl
Gets the embedded user database JDBC URL. For usage with the appropriate driver.- Returns:
- Embedded user database JDBC URL or
nullon error
-