Connect Java with SQL Server 2017 in Eclipse Oxygen

1

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?

    
asked by Robert Gomez 05.11.2017 в 03:31
source

2 answers

3

It seems that your project does not know the classes contained in the library sqljdbc42.jar

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 should go to the project properties (Right button on the project> Properties), go to the "Java Build Path" tab, and in the "Libraries" section click on the "Add JARs" button and you select the file sqlserver42.jar

    
answered by 05.11.2017 / 11:09
source
1

Maybe I miss the library that comes with the driver for JDBC for sqlserver is the * .dll that is in the folder (auth), you have to put it in your main project. They come for two x86 and x64 architectures. Then restart your SQLServer service to save changes to the SQLserver configuration manager.

    
answered by 26.08.2018 в 23:14