JDBC connectivity with SQL Server 2012 using sqljdbc4.1jar
During my college days of MCA I used to face many difficulties in coding. I have also faced the difficulty of JDBC connectivity using JDK 8 with SQL Server 2012. After visiting lot many websites and searching over internet I didn't got the solution. I just used to get the code over the code, but not for which version the jar file to be used. It was the problem that sqljdbc4.0 not works above 6.0 jdk versions. For JDK versions above 6 sqljdbc4.1 works properly.
You can download the jar files from the link https://www.microsoft.com/en-in/download/details.aspx?id=11774
During my college days of MCA I used to face many difficulties in coding. I have also faced the difficulty of JDBC connectivity using JDK 8 with SQL Server 2012. After visiting lot many websites and searching over internet I didn't got the solution. I just used to get the code over the code, but not for which version the jar file to be used. It was the problem that sqljdbc4.0 not works above 6.0 jdk versions. For JDK versions above 6 sqljdbc4.1 works properly.
You can download the jar files from the link https://www.microsoft.com/en-in/download/details.aspx?id=11774
- SQL configuration manager settings before JDBC connection Enable all the client protocols below shown Right click on TCP/IP for properties settings of port no 1433 Change TCP port to 1433 for all
- Now restart the SQL server shown below
- Now place the sqljdbc_auth.dll in C:\Program Files\Java\jre1.8.0_40\lib location
- Check the below code for JDBC connectivity with SQL Server
- import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcSQLServerConnection {
public static void main(String[] args) {
Connection conn = null;
try {
String dbURL = "jdbc:sqlserver://localhost:1433;databaseName=DatabaseName;integratedSecurity=true;";
conn = DriverManager.getConnection(dbURL);
if (conn != null) {
DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
System.out.println("Driver name: " + dm.getDriverName());
System.out.println("Driver version: " + dm.getDriverVersion());
System.out.println("Product name: " + dm.getDatabaseProductName());
System.out.println("Product version: " + dm.getDatabaseProductVersion());
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
}
ouput:Driver name: Microsoft JDBC Driver 4.1 for SQL Server
Driver version: 4.1.5605.100
Product name: Microsoft SQL Server
Product version: 11.00.5058




