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:
You added the jar with the sqlserver driver in the project’s classpath?
– user28595
yes.... is sqljdbc.jar in summer 3.0 to connect to sqlserver 2000
– alexjosesilva
Remove this
Class.forName(DRIVER2);
is no longer needed in java6.– user28595
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
.– Caffé
Now the error is No driver suite found for jdbc:microsoft:sqlserver://server:1433, user, password
– alexjosesilva
The identification of the "subprotocol" in the connection string, "jdbc:microsoft:sqlserver://", is wrong. The correct is
jdbc:sqlserver://
.– Caffé
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.– Caffé
As our colleague @Caffé said, the tab is incorrect, it is used
;
to separate connection url, user and password.– user28595