Azure Java "Web app with MySQL in-app" having Communications link failure to database -


i trying deploy java spring-mvc web app azure, having trouble on connecting mysql in-app.

after deployed, have updated host, port, username , password in xml according connection string in

/data/mysql/mysqlconnstr_localdb.txt

any helps on this? side question, how connection string in java? if port number changed, not need update xml.

encounter error:

type exception report  message request processing failed; nested exception org.springframework.jdbc.cannotgetjdbcconnectionexception: not jdbc connection; nested exception com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure  description server encountered unexpected condition prevented fulfilling request.  exception  org.springframework.web.util.nestedservletexception: request processing failed; nested exception org.springframework.jdbc.cannotgetjdbcconnectionexception: not jdbc connection; nested exception com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure  last packet sent server 0 milliseconds ago. driver has not received packets server.     org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:982)     org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:872)     javax.servlet.http.httpservlet.service(httpservlet.java:661)     org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:846)     javax.servlet.http.httpservlet.service(httpservlet.java:742)     org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) root cause  org.springframework.jdbc.cannotgetjdbcconnectionexception: not jdbc connection; nested exception com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure  last packet sent server 0 milliseconds ago. driver has not received packets server.     org.springframework.jdbc.datasource.datasourceutils.getconnection(datasourceutils.java:80)     org.springframework.jdbc.core.jdbctemplate.execute(jdbctemplate.java:394)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:474)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:484)     jbr.springmvc.dao.userdaoimpl.validateuser(userdaoimpl.java:44)     jbr.springmvc.service.userserviceimpl.validateuser(userserviceimpl.java:26)     jbr.springmvc.controller.logincontroller.loginprocess(logincontroller.java:28)     sun.reflect.nativemethodaccessorimpl.invoke0(native method)     sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     java.lang.reflect.method.invoke(method.java:498)     org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221)     org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:136)     org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:114)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlermethod(requestmappinghandleradapter.java:827)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:738)     org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85)     org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:963)     org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:897)     org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:970)     org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:872)     javax.servlet.http.httpservlet.service(httpservlet.java:661)     org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:846)     javax.servlet.http.httpservlet.service(httpservlet.java:742)     org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) root cause  com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure  last packet sent server 0 milliseconds ago. driver has not received packets server.     sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62)     sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45)     java.lang.reflect.constructor.newinstance(constructor.java:423)     com.mysql.jdbc.util.handlenewinstance(util.java:406)     com.mysql.jdbc.sqlerror.createcommunicationsexception(sqlerror.java:1074)     com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2209)     com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:776)     com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:46)     sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62)     sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45)     java.lang.reflect.constructor.newinstance(constructor.java:423)     com.mysql.jdbc.util.handlenewinstance(util.java:406)     com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:352)     com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:284)     java.sql.drivermanager.getconnection(drivermanager.java:664)     java.sql.drivermanager.getconnection(drivermanager.java:208)     org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdrivermanager(drivermanagerdatasource.java:153)     org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdriver(drivermanagerdatasource.java:144)     org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnectionfromdriver(abstractdriverbaseddatasource.java:196)     org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnection(abstractdriverbaseddatasource.java:159)     org.springframework.jdbc.datasource.datasourceutils.dogetconnection(datasourceutils.java:111)     org.springframework.jdbc.datasource.datasourceutils.getconnection(datasourceutils.java:77)     org.springframework.jdbc.core.jdbctemplate.execute(jdbctemplate.java:394)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:474)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:484)     jbr.springmvc.dao.userdaoimpl.validateuser(userdaoimpl.java:44)     jbr.springmvc.service.userserviceimpl.validateuser(userserviceimpl.java:26)     jbr.springmvc.controller.logincontroller.loginprocess(logincontroller.java:28)     sun.reflect.nativemethodaccessorimpl.invoke0(native method)     sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     java.lang.reflect.method.invoke(method.java:498)     org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221)     org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:136)     org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:114)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlermethod(requestmappinghandleradapter.java:827)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:738)     org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85)     org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:963)     org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:897)     org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:970)     org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:872)     javax.servlet.http.httpservlet.service(httpservlet.java:661)     org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:846)     javax.servlet.http.httpservlet.service(httpservlet.java:742)     org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) root cause  com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure  last packet sent server 0 milliseconds ago. driver has not received packets server.     sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62)     sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45)     java.lang.reflect.constructor.newinstance(constructor.java:423)     com.mysql.jdbc.util.handlenewinstance(util.java:406)     com.mysql.jdbc.sqlerror.createcommunicationsexception(sqlerror.java:1074)     com.mysql.jdbc.mysqlio.<init>(mysqlio.java:343)     com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2132)     com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:776)     com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:46)     sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62)     sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45)     java.lang.reflect.constructor.newinstance(constructor.java:423)     com.mysql.jdbc.util.handlenewinstance(util.java:406)     com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:352)     com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:284)     java.sql.drivermanager.getconnection(drivermanager.java:664)     java.sql.drivermanager.getconnection(drivermanager.java:208)     org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdrivermanager(drivermanagerdatasource.java:153)     org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdriver(drivermanagerdatasource.java:144)     org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnectionfromdriver(abstractdriverbaseddatasource.java:196)     org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnection(abstractdriverbaseddatasource.java:159)     org.springframework.jdbc.datasource.datasourceutils.dogetconnection(datasourceutils.java:111)     org.springframework.jdbc.datasource.datasourceutils.getconnection(datasourceutils.java:77)     org.springframework.jdbc.core.jdbctemplate.execute(jdbctemplate.java:394)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:474)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:484)     jbr.springmvc.dao.userdaoimpl.validateuser(userdaoimpl.java:44)     jbr.springmvc.service.userserviceimpl.validateuser(userserviceimpl.java:26)     jbr.springmvc.controller.logincontroller.loginprocess(logincontroller.java:28)     sun.reflect.nativemethodaccessorimpl.invoke0(native method)     sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     java.lang.reflect.method.invoke(method.java:498)     org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221)     org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:136)     org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:114)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlermethod(requestmappinghandleradapter.java:827)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:738)     org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85)     org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:963)     org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:897)     org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:970)     org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:872)     javax.servlet.http.httpservlet.service(httpservlet.java:661)     org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:846)     javax.servlet.http.httpservlet.service(httpservlet.java:742)     org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) root cause  java.net.socketexception: permission denied: connect     java.net.twostacksplainsocketimpl.socketconnect(native method)     java.net.abstractplainsocketimpl.doconnect(abstractplainsocketimpl.java:350)     java.net.abstractplainsocketimpl.connecttoaddress(abstractplainsocketimpl.java:206)     java.net.abstractplainsocketimpl.connect(abstractplainsocketimpl.java:188)     java.net.plainsocketimpl.connect(plainsocketimpl.java:172)     java.net.sockssocketimpl.connect(sockssocketimpl.java:392)     java.net.socket.connect(socket.java:589)     java.net.socket.connect(socket.java:538)     java.net.socket.<init>(socket.java:434)     java.net.socket.<init>(socket.java:244)     com.mysql.jdbc.standardsocketfactory.connect(standardsocketfactory.java:253)     com.mysql.jdbc.mysqlio.<init>(mysqlio.java:292)     com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2132)     com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:776)     com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:46)     sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62)     sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45)     java.lang.reflect.constructor.newinstance(constructor.java:423)     com.mysql.jdbc.util.handlenewinstance(util.java:406)     com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:352)     com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:284)     java.sql.drivermanager.getconnection(drivermanager.java:664)     java.sql.drivermanager.getconnection(drivermanager.java:208)     org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdrivermanager(drivermanagerdatasource.java:153)     org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdriver(drivermanagerdatasource.java:144)     org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnectionfromdriver(abstractdriverbaseddatasource.java:196)     org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnection(abstractdriverbaseddatasource.java:159)     org.springframework.jdbc.datasource.datasourceutils.dogetconnection(datasourceutils.java:111)     org.springframework.jdbc.datasource.datasourceutils.getconnection(datasourceutils.java:77)     org.springframework.jdbc.core.jdbctemplate.execute(jdbctemplate.java:394)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:474)     org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:484)     jbr.springmvc.dao.userdaoimpl.validateuser(userdaoimpl.java:44)     jbr.springmvc.service.userserviceimpl.validateuser(userserviceimpl.java:26)     jbr.springmvc.controller.logincontroller.loginprocess(logincontroller.java:28)     sun.reflect.nativemethodaccessorimpl.invoke0(native method)     sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     java.lang.reflect.method.invoke(method.java:498)     org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221)     org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:136)     org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:114)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlermethod(requestmappinghandleradapter.java:827)     org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:738)     org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85)     org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:963)     org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:897)     org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:970)     org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:872)     javax.servlet.http.httpservlet.service(httpservlet.java:661)     org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:846)     javax.servlet.http.httpservlet.service(httpservlet.java:742)     org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) note full stack trace of root cause available in server logs. 

the web app working fine in local, able connect , insert data database.

appreciate helps.

depending on description of issue, seems you've written mysql in-app configuration information constant in xml file.

however,it's important know port in configuration parameters changes randomly application restarts. need configure connectstring dynamically.

you find configuration information connection in mysqlconnstr_localdb.txt mentioned.actually,mysqlconnstr_localdb environment variable fetch in java via getenv method.

you refer code below re-configure mysql connection parameters dynamically.

    string connectstring = system.getenv("mysqlconnstr_localdb");      response.getwriter().append("connectstring: " + connectstring);      string database = "";     string port = "";     string username = "";     string password = "";      string[] strarray = connectstring.split(";");     (int = 0; < strarray.length; i++) {         string[] paramarray = strarray[i].split("=");         switch (i) {         case 0:             database = paramarray[1];             continue;         case 1:             port = paramarray[1];             continue;         case 2:             username = paramarray[1];             continue;         case 3:             password = paramarray[1];             continue;         }     }      string url = "jdbc:mysql://" + port + "/" + database + "?"             + "user=" + username + "&password=" + password + "&useunicode=true&characterencoding=utf8";      response.getwriter().append("url:" + url);      try {         class.forname("com.mysql.jdbc.driver");          connection conn = drivermanager.getconnection(url);          response.getwriter().append("     connect success");          statement stmt = conn.createstatement();          string sql = "create table student(no char(20),name varchar(20),primary key(no))";          int result = stmt.executeupdate(sql);          response.getwriter().append("     insert result" + result);      } catch (exception e) {         e.printstacktrace();     } 

hope helps you.


update answer

please check whether <environmentvariable name="java_opts" value="-djava.net.preferipv4stack=true" /> configured in web.config file on kudu.

the container needs configured ipv4 traffic mentioned here.

you refer solutions thread solving "communications link failure" jdbc , mysql , more details mysql in-app here.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -