Erro na conexao com banco mysql apos alguns segundos

3 respostas
hhullck
Meu sistema esta dando um erro apos eu ficar cerca de 30seg, sem comunicar com banco, OBS: Se eu ficar fazendo comunicação com ele o tempo todo não da o erro. O erro e :
run:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 123.583 milliseconds ago.  The last packet sent successfully to the server was 13 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:409)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3056)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2942)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3485)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2690)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1465)
        at Comum.ExecutaSqls.ExecutaSql(ExecutaSqls.java:25)
        at CadastroDeRua.FunçoesRua.consultaRua(FunçoesRua.java:81)
        at CadastroDeRua.CadastrodeRua.<init>(CadastrodeRua.java:58)
        at br.DaysOfEvolution.telas.ChamaTelas.jMenuCadRuaActionPerformed(ChamaTelas.java:375)
        at br.DaysOfEvolution.telas.ChamaTelas.access$400(ChamaTelas.java:34)
        at br.DaysOfEvolution.telas.ChamaTelas$7.actionPerformed(ChamaTelas.java:222)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
        at java.awt.Component.processMouseEvent(Component.java:6263)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6028)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2503)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2953)
        ... 40 more
java.lang.NullPointerException
        at CadastroDeRua.FunçoesRua.consultaRua(FunçoesRua.java:84)
        at CadastroDeRua.CadastrodeRua.<init>(CadastrodeRua.java:58)
        at br.DaysOfEvolution.telas.ChamaTelas.jMenuCadRuaActionPerformed(ChamaTelas.java:375)
        at br.DaysOfEvolution.telas.ChamaTelas.access$400(ChamaTelas.java:34)
        at br.DaysOfEvolution.telas.ChamaTelas$7.actionPerformed(ChamaTelas.java:222)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
        at java.awt.Component.processMouseEvent(Component.java:6263)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6028)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

o codigo da minha classe conexao é:

package br.DaysOfEvolution.funcoesBanco;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *09/08/10 as 17:18h
 * @author Neylon
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;

public class ConexaoBanco {
        private static ConexaoBanco instancia;
        private static Connection conn;
	public static Connection connection = null;//gerencia a conexao
        public Statement statement = null;//instrucao de consulta
        public ResultSet result = null;//gerencia resultados
	private String servidor = null;
	private static String usuario = null;
	private static String senha = null;
	private static String url = null;
	private static String jdbcDriver = null;
	private String banco = null;
	private String ender = null;
	private String porta = null;
   
   
//construtor
    private void ConexaoBanco(){
    	jdbcDriver = "org.gjt.mm.mysql.Driver";
    	/*servidor = "localhost";
    	usuario = "root";//Usuario do bancoo
    	senha = "";//senha do banco
    	banco= "pintounovidades";//nome do banco em uso
         ender = "jdbc:mysql://";*/
        servidor = "dbmy0020.whservidor.com";
    	usuario = "yuricosta_4";//Usuario do bancoo
    	senha = "teste123";//senha do banco
    	banco= "yuricosta_4";//nome do banco em uso    	
    	ender = "jdbc:mysql://";
    	porta = "3306";
        //URL do banco de dados
    	url = ender + servidor + ":"+porta+"/" + banco + "?useUnicode=true&characterEncoding=utf8";
    }//fim do metodo Conexao

//conecta no banco
    private Connection connect() throws SQLException {
    	try{
    	  Class.forName("com.mysql.jdbc.Driver");
    	 // connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/pintounovidades","root","");
           connection = DriverManager.getConnection("jdbc:mysql://dbmy0020.whservidor.com:3306/yuricosta_7",
                   "yuricosta_4","casa");
           
          return connection;
    	}catch (ClassNotFoundException e){
    	    throw new SQLException(e.getMessage());
            //e.printStackTrace();
    	}catch (SQLException e){
            throw new SQLException(e.getMessage());
    		//e.printStackTrace();
    		}
    	  }//fim do metodo getConeection

   
   //Fecha conecao com BD.
    public void closeConnection(){
    	if(connection != null){
    		try{
    			connection.close();
    	}catch (SQLException e){
    		e.printStackTrace();
    	}
       }
    }//fim do metodo closeConnection

    public static Connection getConexao() throws SQLException{
        if ( conn == null )
        {
          instancia = new ConexaoBanco();
          conn = instancia.connect();
        }
        return conn;
    }//fim do metodo get Instancia

    
   }//fim da classe ConexaoBanco

alguem pode me ajudar ?

3 Respostas

nel

Oi!

Veja se não está dando close na sua conexão em um dado momento.
Por favor, poste corretamente o código com as tags code para melhor análise.

Abraços.

hhullck

nel:
Oi!

Veja se não está dando close na sua conexão em um dado momento.
Por favor, poste corretamente o código com as tags code para melhor análise.

Abraços.

Eu ja verifiquei isso !!
Eu meu sistema não da close em nenhum momento na conexão .

C

então experimenta fechar a conexao a cada operacao =P

Criado 28 de julho de 2011
Ultima resposta 28 de jul. de 2011
Respostas 3
Participantes 3