This package provides a utility class for managing JDBC (Java Database Connectivity) connections to a SQL Server database.
The JDBC
class in this package is designed to simplify the process of establishing a connection to a SQL Server database using properties specified in a configuration file (db.properties
). It also provides a method to close the database connection.
-
Setup Properties:
Before using the
JDBC
class, make sure to set up thedb.properties
file with the required database connection information. The properties file should be located atsrc/main/java/util/Database/db.properties
. -
Instantiate JDBC:
Create an instance of the
JDBC
class, which automatically initializes a database connection using the properties from thedb.properties
file.JDBC jdbc = new JDBC();
Get Connection:
- Retrieve the established database connection using the getConnection method.
Connection connection = jdbc.getConnection();
- Close Connection:
When done using the database, close the connection using the databaseClose method.
jdbc.databaseClose();
The db.properties file should include the following properties:
userName
The username for connecting to the database.
password
The password for connecting to the database.
ENCRYPT
Encryption setting for the connection.
databaseName
The name of the database.
IP
The IP of the database.
port
The port number for the database connection.
JDBC -> https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16