Instalei o MySQL (5.1.38 ) aqui no meu Windows Vista 64bits, adicionei o Connector do MySQL (mysql-connector-java-5.1.8-bin.jar) ao buildpath do meu projeto e estou enfrentando o seguinte problema quando tento utilizar qualquer conexão com o MySQL ocorrendo o seguinte erro:
[quote]
Conectando ao banco
Exception in thread “main” com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2120)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:723)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:11)
at br.com.caelum.jdbc.TestaConexao.main(TestaConexao.java:10)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:335)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2043)
… 13 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.(Unknown Source)
at java.net.Socket.(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:284)
… 14 more[/quote]
Minhas classes que estou utilizando para realizar o teste de conexão:
public class ConnectionFactory {
public static Connection getConnection() throws SQLException {
try {
Class.forName(“com.mysql.jdbc.Driver”);
System.out.println(“Conectando ao banco”);
return DriverManager.getConnection (“jdbc:mysql://localhost/teste”, “root”, “admin”);
} catch (ClassNotFoundException e) {
throw new SQLException (e.getMessage());
}
}
}[/code]
import java.sql.Connection;
import java.sql.SQLException;
public class TestaConexao {
public static void main(String[] args) throws SQLException {
Connection con = ConnectionFactory.getConnection();
con.close();
}
}
Meu JDK é o 1.6.0_02.
A porta liberada no Firewall para o MySQL é a 3306 e a senha do usuário root é admin mesmo como coloquei na String de configuração da classe ConnectionFactory.
Será que comi bola ao configurar o MySQL ou o Connector está errado? Eu me lembro de ter feito esse procedimento no meu Windows Vista de 32bits à algum tempo e ele funcionou normalmente, há diferença na configuração e ou algum JDK especifico para SOs de 32bits e 64bits?
@Rubensdemelo
Creio que sim, pelo tray icon o servidor aparece como iniciado (play) e consigo acessar a base e realizar operações na mesma pelo próprio MySQL.
@wbdsjunior
Já cheguei a tentar anteriormente passando a porta da forma como você colocou e mesmo assim ocorre erro.
estou com o mesmo problema e não consigui resolver ainda, ja troquei os drivers, ja coloquei 127.0.0.1, ja coloquei com porta e sem porta e nunca da certo
alguem me ajuda, faz uma semana que tento arrumar isso e não consigo,
Minha classe de conexão é exatamente igual a sua.
A única diferença é que estou usando o linux 64 bits.
erro:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 1,253,243,251,915 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2214)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:773)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at br.ti.bolao.dao.Conexao.getConnection(Conexao.java:17)
at br.ti.bolao.dao.UsuarioDao.main(UsuarioDao.java:42)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 1,253,243,251,908 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2137)
... 13 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:215)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:290)
... 14 more
Java Result: 1
Pessoal, trazendo de volta o tópico, estou tendo o mesmo erro que o pessoal relatou acima:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Estou utilizando JSE/MySql. O curioso é que quando tento fazer a conexão através do método “main” funciona… Agora se tento conectar na action do botão, por exemplo, não funciona!
[quote=alexandrejtms]Pessoal, trazendo de volta o tópico, estou tendo o mesmo erro que o pessoal relatou acima:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Estou utilizando JSE/MySql. O curioso é que quando tento fazer a conexão através do método “main” funciona… Agora se tento conectar na action do botão, por exemplo, não funciona!
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2120)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ConnectionDataBase.ConnectionFactory.getConnection(ConnectionFactory.java:70)
at DAO.CarDao.<init>(CarDao.java:36)
at AutoGestGUI.frmiCar.<init>(frmiCar.java:162)
at AutoGestGUI.frmMainMenu.getCarFrame(frmMainMenu.java:182)
at AutoGestGUI.frmMainMenu.initForms(frmMainMenu.java:403)
at Main.main(Main.java:15)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
[quote=henrriquetec]só conseguimos resolver o problema por partes!!!
primeiro: certifique se realmente o seu banco de dados esteja funcionando. isso inclui (porta aberta, usuario e senha, ip, permissões) etc etc
se utilizar o linux pode usar o nmap localhost
utilize algum programa para se conectar ao banco existem vários. crie algumas tabelas
Communications link failure = comunicação falhou
Abraços[/quote]
Obrigado pelas dicas!
Já descobri qual era o erro. Eu estou a ler os dados para a ligação atraves de um ficheiro e havia um pequeno bug na leitura desse mesmo ficheiro, criando assim um erro na Sting de ligação ao MySQL.