我似乎无法将jdbc转换为AWS RDS。 这是我的错误:
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
这就是我的application.properties文件的样子。
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://xxxx.us-east-1.rds.amazonaws.com:3306/xxxx
spring.datasource.username=admin
spring.datasource.password=xxxx
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=true
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.html
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
#spring.thymeleaf.mode=LEGACYHTML5
和我的配置文件
package gov.mycolorado.oauth2;
import org.springframework.context.annotation.Configuration;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@Configuration
public class ConnectionConfig {
private static Connection getRemoteConnection() throws SQLException {
if (System.getProperty("RDS_HOSTNAME") != null) {
try {
Class.forName("org.mysql.Driver");
String dbName = System.getProperty("RDS_DB_NAME");
String userName = System.getProperty("RDS_USERNAME");
String password = System.getProperty("RDS_PASSWORD");
String hostname = System.getProperty("RDS_HOSTNAME");
String port = System.getProperty("RDS_PORT");
String jdbcUrl = "jdbc:mysql://XXX:3306/XXX?user=admin&password=XXX";
Connection con = DriverManager.getConnection(jdbcUrl);
return con;
// }
//// catch (ClassNotFoundException e) { logger.warn(e.toString());}
//// catch (SQLException e) { logger.warn(e.toString());}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
return null;
}
}
有人有什么建议吗?
jdbc
用于将Java连接到在PC上创建的ODBC连接。 您是否创建了到DB的ODBC连接? 也许您应该使用MySQL Java DB类而不是JDBC?