Class Database
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.Database
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public final class Database extends java.lang.Object implements java.lang.AutoCloseable
Database object that allows communication with a SQL database.- Since:
- 1.3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Database.Connection
The object that stores tasks related to the connection, usegetConnection()
to access methods.class
Database.Info
The object that stores the database info, usegetInfo()
to access methods.static class
Database.Settings
Allows setting and retrieval of settings values from a database, usegetSettings()
to access methods.class
Database.Tasks
The object that stores methods to complete database tasks, usegetTasks()
to access methods.
-
Constructor Summary
Constructors Constructor Description Database(DatabaseConnectionInfo info)
Creates a database object with the specified parameters.Database(java.lang.String dbFilePath, DatabaseType type)
Creates a database object with the specified parameters.Database(java.lang.String dbFilePath, java.lang.String username, java.lang.String password, DatabaseType type)
Creates a database object with the specified parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Releases this database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed, It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.boolean
equals(java.lang.Object o)
Database.Connection
getConnection()
Allows management of the connection to the database.Database.Info
getInfo()
Returns info about the database.Database.Settings
getSettings()
Allows setting and retrieval of settings values from the database.Database.Tasks
getTasks()
Runs tasks against the database.int
hashCode()
java.lang.String
toString()
-
-
-
Constructor Detail
-
Database
public Database(java.lang.String dbFilePath, java.lang.String username, java.lang.String password, DatabaseType type) throws java.sql.SQLException
Creates a database object with the specified parameters.- Parameters:
dbFilePath
- File path to the database to connect tousername
- Username to use to connect to the database, ignored if blankpassword
- Password to use to connect to the database, ignored if blanktype
- The database type- Throws:
java.sql.SQLException
- if initial connection fails- Since:
- 1.4.0, constructor connects to database by running getConnection().connect().
-
Database
public Database(java.lang.String dbFilePath, DatabaseType type) throws java.sql.SQLException
Creates a database object with the specified parameters.- Parameters:
dbFilePath
- File path to the database to connect totype
- The database type- Throws:
java.sql.SQLException
- if initial connection fails
-
Database
public Database(DatabaseConnectionInfo info) throws java.sql.SQLException
Creates a database object with the specified parameters.- Parameters:
info
- An object containing the database path, username, password and database type- Throws:
java.sql.SQLException
- if initial connection fails
-
-
Method Detail
-
getConnection
public Database.Connection getConnection()
Allows management of the connection to the database.- Returns:
- instance of the Connection class
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getInfo
public Database.Info getInfo()
Returns info about the database.- Returns:
- instance of the Info class
-
getTasks
public Database.Tasks getTasks()
Runs tasks against the database.- Returns:
- instance of the Tasks class
-
getSettings
public Database.Settings getSettings()
Allows setting and retrieval of settings values from the database.- Returns:
- instance of the Settings class
-
close
public void close() throws java.sql.SQLException
Releases this database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed, It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.sql.SQLException
-
-