Skip to content

Commit e4df9f7

Browse files
committed
initial commit
0 parents  commit e4df9f7

File tree

4 files changed

+167
-0
lines changed

4 files changed

+167
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ms-sqlserver-jdbc-tester
2+
3+
A simple Spring Boot command line app to test JDBC connection to SQL Server database.
4+
5+
## How to run
6+
7+
Download the JAR from release page or alternatively download the code and build the jar file:
8+
9+
```
10+
mvn clean package
11+
```
12+
13+
Execute the JAR file. Example below:
14+
15+
```
16+
java -jar target/ms-sqlserver-jdbc-1.0.jar ""jdbc:sqlserver://mydatabase.db.windows.net:1433;database=example@user.com;user=myser@example.com;password=secret123;encrypt=true;trustServerCertificate=true;loginTimeout=90;authentication=ActiveDirectoryPassword"
17+
```
18+
19+
20+
## License
21+
(The MIT License)
22+
23+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pom.xml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.ms-sqlserver-jdbc</groupId>
8+
<artifactId>ms-sqlserver-jdbc</artifactId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.5.4.RELEASE</version>
17+
</parent>
18+
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>log4j</groupId>
28+
<artifactId>log4j</artifactId>
29+
<version>1.2.17</version>
30+
</dependency>
31+
32+
33+
<dependency>
34+
<groupId>org.slf4j</groupId>
35+
<artifactId>slf4j-log4j12</artifactId>
36+
<version>1.7.26</version>
37+
</dependency>
38+
39+
40+
<dependency>
41+
<groupId>net.minidev</groupId>
42+
<artifactId>json-smart</artifactId>
43+
<version>2.3</version>
44+
</dependency>
45+
46+
47+
<dependency>
48+
<groupId>com.microsoft.azure</groupId>
49+
<artifactId>msal4j</artifactId>
50+
<version>1.9.0</version>
51+
</dependency>
52+
53+
54+
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
55+
<dependency>
56+
<groupId>com.microsoft.sqlserver</groupId>
57+
<artifactId>mssql-jdbc</artifactId>
58+
<version>9.2.0.jre8</version>
59+
<scope>system</scope>
60+
<systemPath>${basedir}/src/main/lib/mssql-jdbc-9.2.0.jre8.jar</systemPath>
61+
</dependency>
62+
63+
</dependencies>
64+
65+
<repositories>
66+
67+
<repository>
68+
<id>Central</id>
69+
<name>Central</name>
70+
<url>https://repo1.maven.org/maven2/</url>
71+
<layout>default</layout>
72+
</repository>
73+
</repositories>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-jar-plugin</artifactId>
80+
81+
<configuration>
82+
<archive>
83+
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
84+
</archive>
85+
</configuration>
86+
</plugin>
87+
<plugin>
88+
<groupId>org.springframework.boot</groupId>
89+
<artifactId>spring-boot-maven-plugin</artifactId>
90+
<configuration>
91+
<includeSystemScope>true</includeSystemScope>
92+
</configuration>
93+
</plugin>
94+
95+
</plugins>
96+
</build>
97+
98+
</project>

src/main/java/Main.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
2+
import org.apache.log4j.BasicConfigurator;
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.sql.*;
7+
8+
9+
10+
public class Main {
11+
final static Logger LOG = LoggerFactory.getLogger(Main.class);
12+
13+
14+
public static void main(String[] args) throws SQLException, ClassNotFoundException {
15+
16+
BasicConfigurator.configure();
17+
18+
if (args.length != 1) {
19+
LOG.info("Invalid number of arguments: Must provide JDBC string to test as argument");
20+
return;
21+
}
22+
23+
String jdbcString = args[0];
24+
25+
DriverManager.registerDriver(new SQLServerDriver());
26+
27+
LOG.info("\n ******* Initiating JDBC test with JDBC String..... ******* \n");
28+
29+
Connection connection = DriverManager.getConnection(jdbcString);
30+
Statement statement = connection.createStatement();
31+
ResultSet resultSet = statement.executeQuery("SELECT SUSER_SNAME()");
32+
33+
if (resultSet.next()) {
34+
LOG.info("\n" +
35+
"Connection established!! \n" +
36+
"You have successfully logged on as: " + resultSet.getString(1) + "\n");
37+
}
38+
39+
statement.close();
40+
connection.close();
41+
}
42+
}
43+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Created-By: 1.6.0 (Sun Microsystems Inc.)
3+
Main-Class: Main

0 commit comments

Comments
 (0)