JPA/hiBERNATE COM mYSQL DUVIDA NO USO com.mysql.jdbc.CommunicationsException

1 resposta
P

POR QUE NÃO CONSIGO PEGAR O ERRO PELA EXCEPTION com.mysql.jdbc.CommunicationsException
QUANDO O BANCO ESTÁ FORA DO AR ???

ALGUÉM JÁ PASSOU POR ISSO ???

package br.com.conexao;

import java.sql.SQLException;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
 public class testaPersistsence1 {  
	       
	     /** EntityManagerFactory */  
	     private static EntityManagerFactory emf ;  
	     /** EntityManager */  
	     private static EntityManager        em  ;  
	     /** 
	      * @param args 
	     * @throws SQLException 
	      */  
	     public static void main(String[] args) 
	     {  
	          
	           try{
	        	   System.out.println("Inicio do acesso ");  
	              conecta();  
	      
	           } catch (com.mysql.jdbc.CommunicationsException e) {   
	               System.out.println("Erro ="+e);
	           }      
	           
	     }  
	     
	     
	    	 public static void conecta()  throws com.mysql.jdbc.CommunicationsException{ 
	    	 try {  
	                emf = Persistence.createEntityManagerFactory("ims_create");  
	                System.out.println("Acesso Arquivo xml....");  

                    em  = emf.createEntityManager();  
	                System.out.println("Acesso Local k....");  
	    	 } catch (Exception e) {     
	             throw new com.mysql.jdbc.CommunicationsException(null, 0, e);     
	    	 }catch (Throwable e) {     
	    		 throw new com.mysql.jdbc.CommunicationsException(null, 0, (Exception) e);     
	    	 }finally{  
	             em.close();  
	         }   
	    	 
	     }
	   
	 }
Inicio do acesso 
19:55:37,792  WARN BasicResourcePool:1841 - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@13936e1 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection refused: connect
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2666)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
	at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

1 Resposta

P
try {  
	                emf = Persistence.createEntityManagerFactory("ims");  
	                System.out.println("emf ="+emf);  

                    em  = emf.createEntityManager();  
                    System.out.println("em ="+em);  
  
	    	 } catch (Exception e) {     
	             throw new com.mysql.jdbc.CommunicationsException(null, 0, e);     
	    	 }catch (Throwable e) {     
	    		 throw new com.mysql.jdbc.CommunicationsException(null, 0, (Exception) e);     
	    	 }finally{  
	             //em.close();  
	         }

o mais estranho ainda é que o banco não está no ar e os obejtos ficam instanciados :
não acredito não consigo pegar o erro ???
emf =org.hibernate.ejb.EntityManagerFactoryImpl@16ea269
em =org.hibernate.ejb.EntityManagerImpl@1367e28

Inicio do acesso 
21:10:31,645  WARN BasicResourcePool:1841 - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@b301f2 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION **
Criado 6 de março de 2009
Ultima resposta 6 de mar. de 2009
Respostas 1
Participantes 1