当测试集成开始时,我可以使用以下命令连接到终端上的容器上的MysqL:
MysqL -h 127.0.0.1 -P 32795 -uroot -p
并且每一件事情都很好,但是当我想用java代码连接这个代码时,在java应用程序中连接MysqL:
Class.forName("com.MysqL.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(
"jdbc:MysqL://127.0.0.1:" + System.getProperty("MysqLPort") + "/dashboardmanager","root","root"
);
我收到此错误:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.sqlException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:615) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:866) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:937) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
我试过了:
export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"
和
System.setProperty("java.net.preferIPv4Stack","true");
但没有改变.
Docker Maven Plugin Conf:
MysqL:5.7.11MysqL_ROOT_PASSWORD>rootMysqL_ROOT_PASSWORD>
<MysqL_DATABASE>dashboardmanagerMysqL_DATABASE>
MysqLPort:3306