Skip to content

Maxbleu/SqlServerLibrary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Server Library

What it is

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.

Installation

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);

Methods

The library exposes the following methods to interact with the database:

  • ResultSet executeQueryStatement(String query): Executes a simple SELECT query and returns a ResultSet.
  • void executeUpdateStatement(String query, boolean autoCommit): Executes an INSERT, UPDATE, or DELETE statement. You can control the transaction with the autoCommit flag.
  • ResultSet executeQueryPreparedStatement(String query, Object... parameters): Executes a SELECT query using a PreparedStatement with variable parameters, preventing SQL injection.
  • void executeUpdatePreparedStatement(String query, boolean autoCommit, Object... parameters): Executes an INSERT, UPDATE, or DELETE query using a PreparedStatement with variable parameters.
  • void executeSelectStoreProcedure(String query, Method dataHandler, Object obj, Object... parameters): Executes a stored procedure that returns data. It requires a Method object to handle the resulting ResultSet.
  • void executeUpdateStoreProcedure(String query, boolean autoCommit, Object... parameters): Executes a stored procedure that modifies data.

Technology Stack

  • Language: Java 17
  • Build Tool: Maven
  • Database: Microsoft SQL Server

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Library developed in Java for Microsoft Sql Server

Topics

Resources

License

Stars

Watchers

Forks

Languages