Error connecting to Sqlserver using JAVA JDBC

Asked

Viewed 100 times

0

I’m using the sqlserver lib and my connection class is down here:

public class conexao{

//sqlsever
private static final String USUARIO2 = "usuario";
private static final String SENHA2   = "senha";
private static final String URL2     = "jdbc:microsoft:sqlserver://servidor:1433,usuario,senha";
private static final String DRIVER2  = "com.microsoft.sqlserver.jdbc"; //  JDBC driver


public void ConexaoAbrir(){
    try {  
        Class.forName(DRIVER2);

        Connection conn = DriverManager.getConnection(URL2, USUARIO2, SENHA2);     
    } 
        catch (SQLException e) {
            JOptionPane.showMessageDialog(null,"SQL Exception: "+ e.toString());
    } 
        catch (ClassNotFoundException cE) {
            JOptionPane.showMessageDialog(null,"Class Not Found Exception: "+ cE.toString());
    }
}

}

Class error:

bug

  • You added the jar with the sqlserver driver in the project’s classpath?

  • yes.... is sqljdbc.jar in summer 3.0 to connect to sqlserver 2000

  • Remove this Class.forName(DRIVER2); is no longer needed in java6.

  • 1

    You are treating "com.microsoft.sqlserver.jdbc" as if it were a class, but this is the name of the package. The class name is com.microsoft.sqlserver.jdbc.SQLServerDriver.

  • Now the error is No driver suite found for jdbc:microsoft:sqlserver://server:1433, user, password

  • 1

    The identification of the "subprotocol" in the connection string, "jdbc:microsoft:sqlserver://", is wrong. The correct is jdbc:sqlserver://.

  • 1

    Another thing: the property separator in the connection string is semicolon (you are using comma). And I’ve never seen it to just enter the values - also enter the name of the properties, like this: user=usuario;password=senha;. Look for an example of a connection string in google.

  • As our colleague @Caffé said, the tab is incorrect, it is used ; to separate connection url, user and password.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.