This is a simple Java library designed to facilitate interaction with a Microsoft SQL Server database. It provides a straightforward way to execute raw SQL queries, use prepared statements, and call stored procedures, handling the database connection and resource management.
This project is built with Maven. To include it in your project, add the following dependency to your pom.xml:
<dependency>
<groupId>com.example.SqlServerLibrary</groupId>
<artifactId>SqlServerLibrary</artifactId>
<version>1.1.3</version>
</dependency>Then, you can instantiate the library. The library includes a helper method to build the connection string:
import com.example.SqlServerLibrary.SqlServerLibrary;
import com.example.SqlServerLibrary.ISqlServerLibrary;
// Build the connection string
String connectionString = SqlServerLibrary.getConnectionString(
"your_server_address",
"your_database_name",
"your_user",
"your_password",
true // trustServerCertificate
);
// Create an instance of the library
ISqlServerLibrary dbLibrary = new SqlServerLibrary(connectionString);The library exposes the following methods to interact with the database:
ResultSet executeQueryStatement(String query): Executes a simpleSELECTquery and returns aResultSet.void executeUpdateStatement(String query, boolean autoCommit): Executes anINSERT,UPDATE, orDELETEstatement. You can control the transaction with theautoCommitflag.ResultSet executeQueryPreparedStatement(String query, Object... parameters): Executes aSELECTquery using aPreparedStatementwith variable parameters, preventing SQL injection.void executeUpdatePreparedStatement(String query, boolean autoCommit, Object... parameters): Executes anINSERT,UPDATE, orDELETEquery using aPreparedStatementwith variable parameters.void executeSelectStoreProcedure(String query, Method dataHandler, Object obj, Object... parameters): Executes a stored procedure that returns data. It requires aMethodobject to handle the resultingResultSet.void executeUpdateStoreProcedure(String query, boolean autoCommit, Object... parameters): Executes a stored procedure that modifies data.
- Language:
Java 17 - Build Tool:
Maven - Database:
Microsoft SQL Server
This project is licensed under the MIT License. See the LICENSE file for details.