source

java.sql 푸는 방법SQL 비일시적 연결예외:결과 집합을 읽을 수 없습니다.연결 재설정?

lovecheck 2023. 10. 24. 21:25
반응형

java.sql 푸는 방법SQL 비일시적 연결예외:결과 집합을 읽을 수 없습니다.연결 재설정?

비활성 기간이 지난 후 데이터베이스 코드를 호출할 때 예외가 발생하는 경우

java.sql.SQLNonTransientConnectionException: Could not read resultset: Connection reset
        at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
        at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
        at org.mariadb.jdbc.MySQLStatement.executeQueryEpilog(MySQLStatement.java:264)
        at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:288)
        at org.mariadb.jdbc.MySQLStatement.executeQuery(MySQLStatement.java:302)
        at org.mariadb.jdbc.MySQLStatement.executeQuery(MySQLStatement.java:361)
        at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
        at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
        at com.vimba.database.DBFactory.attemptLoginWithTempPasswordDetails(DBFactory.java:181)
        at com.vimba.database.DBFactory.authenticate(DBFactory.java:131)
        at com.vimba.service.ExposedFunctions.login(ExposedFunctions.java:88)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:210)
        at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:132)
        at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:241)
        at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:74)
        at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:559)
        at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:518)
        at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:503)
        at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:400)
        at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:226)
        at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:375)
        at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:175)
        at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:134)
        at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:159)
        at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:49)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not read resultset: Connection reset
        at org.mariadb.jdbc.internal.mysql.MySQLProtocol.getResult(MySQLProtocol.java:926)
        at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:991)
        at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:281)
        ... 40 more
Caused by: java.net.SocketException: Connection reset

/etc/my.cnf를 변경하여 wait_time out of week을 추가하려고 했지만 변경되지 않았습니다.

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld/mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

# Currently, there are mariadb and community-mysql packages in Fedora.
# This particular config file is included in respective RPMs of both of them,
# so the following settings are general and will be also used by both of them.
# Otherwise the RPMs would be in conflict.
# Settings for particular implementations like MariaDB are then
# defined in appropriate sections; for MariaDB server in [mariadb] section in
# /etc/my.cnf.d/server.cnf (part of mariadb-server).
# It doesn't matter that we set these settings only for [mysqld] here,
# because they will be read and used in mysqld_safe as well.
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqld_safe]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

#one week timeout to see if exception goes
wait_timeout=604800

event_scheduler=on
/etc/my.cnf (END)

이 문제를 해결하는 방법을 아는 사람이 있습니까?

해당 연결 검사를 수행하도록 DBCP를 구성할 수 있습니다.이와 같은 내용을 구성에 추가합니다.

validationQuery="/* ping */ SELECT 1"
testOnBorrow="true"

DBCP는 풀에서 연결을 얻을 때마다 연결이 활성화되어 있는지 확인하여 필요할 때 연결을 삭제하고 새 연결을 만듭니다.

결국 나는 포기하고 매시간마다 데이터베이스를 ping하는 방법을 썼습니다.

public static void pingServer(final BasicDataSource source){
    final Thread serverPing = new Thread(new Runnable() {
        @Override
        public void run() {
            Connection conn = null;
            try {
                while(!Thread.currentThread().isInterrupted()){
                    String sql = "/* ping */ SELECT 1";
                    PreparedStatement st = null;
                    conn = source.getConnection();
                    st = conn.prepareStatement(sql);
                    st.executeUpdate(sql);
                    LOGGER.info("Database connection test successful");
                    DatabaseUtilities.closeConnection(conn);
                    TimeUnit.HOURS.sleep(1);
                }
            } catch (SQLException | InterruptedException e) {
                LOGGER.error("Unable to continue pinging database server", e);
                DatabaseUtilities.closeConnection(conn);
            }
            finally{
                DatabaseUtilities.closeConnection(conn);
            }
        }
    });
    serverPing.setDaemon(true);
    serverPing.start();
}

문자열 변경 jdbcUrl

보낸 사람: 문자열 jdbcUrl = "jdbc:mysql://localhost:3306/web_customer_tracker?usesSSL= false";

받는 사람: 문자열 jdbcUrl = "jdbc:mysql://localhost:3306/web_customer_tracker?usesSSL= false&allowPublicKeyRetrieval= true";

메이븐 파일의 경우

1단계) 폴더 src/메인/리소스 열기

2단계) persistence-mysql.properties 열기

3단계) jdbc.url 변경

부터

jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false

로.

jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&allowPublicKeyRetrieval=true

언급URL : https://stackoverflow.com/questions/25054095/how-to-solve-java-sql-sqlnontransientconnectionexception-could-not-read-results

반응형