I am using Eclipse Oxygen to develop a Java program and I want to use SQL Server 2017 to save the information. I read in other places how to do it, but, it does not work for me.
Steps I've done so far:
- I downloaded the Microsoft JDBC Driver 6.0 for SQL Server .
- I added it to my project in Eclipse Oxygen.
- I added the Driver in the Java Build Path of my project.
- I have my database created using SQL Server Management Studio v17.3.
- In SQL Server Network Configuration, I have TCP / IP and Named Pipes activated.
- In Windows Defender Firewall, I have port 1433 open.
The code I have is:
public class ConexionSQL {
// Librería de SQL
public String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
// Nombre de la base de datos
public String database = "industriaCine";
// Host
public String hostname = "localhost";
// Puerto predeterminado para SQL Server
public String port = "1433";
// Ruta de nuestra base de datos ("integratedSecurity=true" establece que usaremos la autenticación integrada de Windows)
public String url = "jdbc:sqlserver://" + hostname + ";databaseName=" + database + ";integratedSecurity=true";
public Connection conectarSQL() {
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
} catch (ClassNotFoundException | SQLException e) {
JOptionPane.showMessageDialog(null, "SQLException:\n" + e, "Error: conectarSQL()", JOptionPane.ERROR_MESSAGE);
}
return conn;
}
}
In Eclipse I receive these errors in the console:
Nov 05, 2017 9:33:23 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI WARNING: Failed to load the sqljdbc_auth.dll cause: no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionid: fe7aa3ab-3308-4602-9918-ef166b69118
What is missing in order to connect to SQL Server?
Do I have something wrong with the code?