I am using Eclipse Oxygen to develop a Java program and I want to use SQL Server 2017 to save the information. I read on other sites how to do it, but, it doesn't work for me.
Steps I have 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 enabled.
- 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 get 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 do I need to be able to connect to SQL Server?
I have something wrong in the code?
It seems that your project does not know the classes contained in the sqljdbc42.jar library
It is not enough to copy the file to your project, you must add the library to the project from the Built Path.
Have you done this step? If not, you would have to go to the project properties (Right button on the project > Properties), go to the "Java Build Path" tab, and in the "Libraries" section press the "Add JARs" button and select the sqlserver42.jar file
Perhaps you are missing the library that comes along with the JDBC driver for sqlserver is the *.dll that is in the (auth) folder, you have to put it in your main project. They come for two architectures x86 and x64. Then restart your SQLServer service to save the SQLserver configuration manager changes.