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 void
close()
Closes the database.static void
connect()
Connects to the database.static ResultSet
Execute a SQL query on the database.static void
Fill the database with example data.static Connection
get()
Gets the current connection.static DataSource
Gets the data source.static String
Gets the embedded user database JDBC URL.static void
init()
Initialize the database with required schema.static PreparedStatement
preparedStatement
(String query) Create a new prepared statement on the opened database, using the provided SQL query.static Statement
Create a new statement on the opened database.static boolean
validate()
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:
true
if 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
null
on error
-