SqlServer + java

3 respostas
java
R

Ola a todos estou tanando me conectar ao sql Server só que recebo a seguinte mensagem de error:

set 23, 2016 11:17:37 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin

ADVERTÊNCIA: ConnectionID:1 Prelogin error: host srvwin2012 port 49154 Unexpected end of prelogin response after 0 bytes read

Exception in thread main com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host srvwin2012, port 49154 has failed. Error: The driver received an unexpected prelogin response. Please verify the connection properties and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port. Note that this driver can be used only with SQL Server 2000 or later

at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1509)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:1297)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1200)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(SQLServerConnection.java:1054)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:758)

at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:247)

at db.connections.SQL_ServerConnerction.abreConexao(SQL_ServerConnerction.java:45)

at sc.classes.Teste.conexão(Teste.java:22)

at sc.classes.Teste.main(Teste.java:27)

Java Result: 1

Meu método de conexão:

public static  Connection abreConexao() throws SQLException{  
      try 
      {  
  
        Class.forName(DRIVER );  
        Connection con = DriverManager.getConnection(URL,usuario,password);  
        return con;  
  
      } catch (ClassNotFoundException e) {  
               throw new SQLException(e.getMessage());  
  
      }  
}

os parâmetros que passo para conexão ja chequei e estão corretos se alguém puder me ajudar fico grato

3 Respostas

I

Corretos ele podem estar, mas sua máquina pode estar sem acesso.
Usa o netstat e valida

R

testei e no netstat aparece que tem conexão só que aqui no meu código ele fica parado na parte de url,usuario e password não executa o resto fica executando até eu parar manualmente e não da erro:

public static Connection abreConexao() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException{

Class.forName(DRIVER).newInstance();
Connection connection = null;

try {

System.out.println(Connecting database…”);

connection = DriverManager.getConnection(URL,usuario,password);

System.out.println(Database connected!);

} catch (SQLException e) {

throw new RuntimeException(Cannot connect the database!, e);

} finally {

System.out.println(Closing the connection.);

if (connection != null) try { connection.close(); } catch (SQLException ignore) {}

}

return null;

}

J

renato trabalho com sqlserver e este problema deve ser devido ao acesso ao servidor…
observe a porta de conexão com o mesmo… alguma coisa esta errada…
verifique também a versão do sqlserver que vc esta utilizando o seu driver conforme a resposta
esta dizendo que se for um sqlserver anterior ao 2000 ele não ira funcionar muito bem

Criado 23 de setembro de 2016
Ultima resposta 23 de set. de 2016
Respostas 3
Participantes 3