Jump to content

SQL Server ligação


Damon4hire
 Share

Recommended Posts

boas pessoal mais uma vez lol.

Comecei agora as ligações a bd's,

e estou a fazer alguma coisa mal na conecção.

Até agora tenho isto:

protected static Connection connect;

    static {

        try {

            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        } catch(ClassNotFoundException ex) {

            ex.printStackTrace();

            System.exit(1);

        }

    }

    protected LinksBD() throws SQLException {

        initConnection();

    }

   

    protected static void initConnection() throws SQLException {

        connect = DriverManager.getConnection("jdbc:microsoft.sqlserver://localhost; DatabaseName = Loja; integratedSecurity = true");

    }

Mas o mais estranho não é ele não ligar, ele nem sequer dá erros ou excepções, apenas faz o build successful,

quando o tento correr.

Agradeço a ajuda.

Link to comment
Share on other sites

lol ok ja m deu outra coisa.

Uma excepção:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".

java.lang.NullPointerException

Nao tenho firewall activa de momento, incluindo a do windows.

De resto nao sei mexer.

Link to comment
Share on other sites

mas devo apagar so o ClassForName, o bloco static inteiro, ...?

N percebi 🙂

Isto podes limpar...

        try {

            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        } catch(ClassNotFoundException ex) {

            ex.printStackTrace();

            System.exit(1);

        }

Quanto ao "acontecer alguma coisa"... O que estás a espera que aconteça? Apenas estás a criar a criar uma connection, não estás a fazer nada com ela

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.