我正在开发一个涉及MySQL数据库的学校项目。我们遇到了一个问题,当我们尝试连接到我们的服务器时,我们收到以下错误:
Severe: Exception while deploying the app [FrienDB-Server]
Severe: Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: User nwong already has more than 'max_user_connections' active connections
我们正在使用我们的学校SQL服务器,因此我们无权更改最大连接数。我试过杀死MySQL Workbench上的连接,但这不起作用。我们如何解决这个问题?
这是我的DatabaseConnection类
package friendb.server.util;
import java.util.Map;
import java.util.HashMap;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
/**
* Utility class for database connections.
* @author Evan Guby
*/
public final class DatabaseConnection
{
private static final String PERSISTENCE_UNIT_NAME = "FrienDB";
private static Map PROPERTIES = new HashMap();
private static final String USERNAME = "nwong";
private static final String PASSWORD = "108857304";
/**
* Creates and returns an entity manager connected to the persistence unit.
* @return
*/
public static EntityManager getEntityManager()
{
PROPERTIES.put(PersistenceUnitProperties.JDBC_USER, USERNAME);
PROPERTIES.put(PersistenceUnitProperties.JDBC_PASSWORD, PASSWORD);
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, PROPERTIES);
return emf.createEntityManager();
}
}
在我尝试通过服务器从我们的客户端访问数据库中的某些内容时,它运行的极少数情况下我收到此错误:
Caused by: javax.transaction.xa.XAException: com.sun.appserv.connectors.internal.api.PoolingException: javax.resource.spi.LocalTransactionException: Communications link failure
The last packet successfully received from the server was 1,575,262 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.