I am trying to connect to a sql server database, but I am not succeeding. Here is the connection class and test method:
public class ConexaoBanco {
public static final String user = "sa";
public static final String pswd = "**********";
public static Connection conexao() {
Connection con = null;
final String jdbcDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
final String caminho= "jdbc:microsoft:sqlserver://localhost:1433;databaseName=cliente";
try {
Class.forName(jdbcDriver);
con = DriverManager.getConnection(caminho, user, pswd);
} catch (SQLException e) {
e.printStackTrace();
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
System.out.println();
}
return con;
}
public static void main(String[] args) {
try {
Connection conex = ConexaoBanco.conexao();
if (conex != null ) {
System.out.println("conectado");
} else {
System.out.println("não conectado");
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}