54 lines
1.5 KiB
Kotlin
54 lines
1.5 KiB
Kotlin
package database
|
|
|
|
import org.mariadb.jdbc.Connection
|
|
import org.tinylog.Logger
|
|
import java.sql.DriverManager
|
|
|
|
/**
|
|
* A class to manage a connection to a MariaDB database.
|
|
*
|
|
* @property address The address of the MariaDB server.
|
|
* @property port The port number of the MariaDB server.
|
|
* @property dbName The name of the database to connect to.
|
|
* @property username The username for the database connection.
|
|
* @property password The password for the database connection.
|
|
*/
|
|
class MariaDB (
|
|
address : String = "localhost",
|
|
port : Int = 3306,
|
|
dbName : String = "aas",
|
|
username : String = "admin",
|
|
password : String = "admin"
|
|
) {
|
|
private var connection : Connection? = null
|
|
var connected : Boolean = false
|
|
var SoundbankList : ArrayList<Soundbank> = ArrayList()
|
|
var MessagebankList : ArrayList<Messagebank> = ArrayList()
|
|
|
|
init {
|
|
try {
|
|
connection = DriverManager.getConnection("jdbc:mariadb://$address:$port/$dbName", username, password) as Connection
|
|
Logger.info("Connected to MariaDB" as Any)
|
|
connected = true
|
|
} catch (e : Exception) {
|
|
Logger.error("Failed to connect to MariaDB: ${e.message}" as Any)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Closes the MariaDB connection.
|
|
*/
|
|
fun close() {
|
|
try {
|
|
connection?.close()
|
|
|
|
Logger.info("Connection to MariaDB closed" as Any)
|
|
} catch (e : Exception) {
|
|
Logger.error("Error closing MariaDB connection: ${e.message}" as Any)
|
|
}
|
|
connected = false
|
|
}
|
|
|
|
|
|
|
|
} |