How to Connect the SQL Server Online Database from the JDBC in Netbeans

Asked

Viewed 729 times

0

I have a question about how to generate the JDBC Java connection URL in the Netbeans IDE to connect to an online SQL Server database.

Below is my code, which did not generate a connection like the database:

  package teste.br.com.DAO;

import java.sql.Connection;
import java.sql.DriverManager;

 public class ConexaoSQLServer {

    Connection con = null;
    String driverDB = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

    String rota = "jdbc:sqlserver//sqlserver01.BASE_DADOS.com.br;databaseName=NOME;user=USER;"
            + "password=PASS;";

    public boolean ConectarBD(){
        try{
            Class.forName(driverDB);
            con = DriverManager.getConnection(rota);
            return true;
        }
        catch(Exception ex){
            ex.getMessage();
            return false;

        }
    }
}

While debugging netbeans, I found that the problem is connecting to the online database.

  • Welcome Igor! Could you edit your question and add the error that is generated? Help the community have help! Thank you very much!

  • Missing port, after host: sqlserver01.BASE_DADOS.com.br:1433

  • Take a look at the connectionstrings.with

  • Actually no error occurred while running, even putting Try catch with the exceptions referring, only to debuggar I realize that my connection is null, I will check if the online database has some property that I did not specify in the url. Thank you so much for your help!

No answers

Browser other questions tagged

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