Hibernate testConnectionOnCheckout not testing connection - mysql

I have connection testing enabled in my hibernate c3p0 properties but even after that i am facing connection issue.
Here is my connection configuration:
hibernate.connection.url = "jdbc:mysql://abc.eu-west-1.rds.amazonaws.com:3306/abc";
hibernate.dialect = "org.hibernate.dialect.MySQLDialect";
hibernate.cache.provider_class = "org.hibernate.cache.NoCacheProvider";
hibernate.hbm2ddl.auto = "update";
hibernate.show_sql = "false";
hibernate.connection.provider_class = "org.hibernate.c3p0.internal.C3P0ConnectionProvider";
hibernate.c3p0.min_size = "50";
hibernate.c3p0.max_size = "50";
hibernate.c3p0.idle_test_period = "100";
hibernate.c3p0.max_statements = "0";
hibernate.c3p0.timeout = "43200";
hibernate.c3p0.preferredTestQuery = "select 1";
hibernate.c3p0.testConnectionOnCheckout = "true";
Despite having enabled hibernate.c3p0.testConnectionOnCheckout i am getting the error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 48,002,613 milliseconds ago. The last packet sent successfully to the server was 48,002,615 milliseconds ago. is longer than the server con
figured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnec
t=true' to avoid this problem.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_192]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_192]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_192]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_192]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377) ~[mysql-connector-java-bin.jar:5.1.33]
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1036) ~[mysql-connector-java-bin.jar:5.1.33]
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3661) ~[mysql-connector-java-bin.jar:5.1.33]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2417) ~[mysql-connector-java-bin.jar:5.1.33]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) ~[mysql-connector-java-bin.jar:5.1.33]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2526) ~[mysql-connector-java-bin.jar:5.1.33]
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4842) ~[mysql-connector-java-bin.jar:5.1.33]
at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:1059) ~[c3p0-0.9.5.1.jar:0.9.5.1]
at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.begin(AbstractLogicalConnectionImplementor.java:67) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:235) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:214) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:52) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1525) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:45) ~[hibernate-entitymanager-5.1.0.Final.jar:5.1.0.Final]
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:66) ~[guice-persist-4.0.jar:?]
at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:77) ~[guice-4.0.jar:?]
...
Shouldn't testConnectionOnCheckout test the connection before performing any query and prevent this kind of error?
If not what should i do to correct this error?

Related

Spring Boot 2.5.3, JdbcBatchItemWriter, MySql 5.7 on RDS, java.io.IOException: Socket is closed

I have a spring batch job that reads from a DB2 instance, does a slight transformation, then inserts into a MySql instance on RDS using a JdbcBatchItemWriter. The job uses multi-thread step via a TaskExecutor to scale. I am setting hikari max pool size and step executor's throttle limit both at 32 which generates an overall throughput of about 700 items/sec. Things hum along nicely for what seems arbitrary amounts of time when I'm suddenly hit with...
Caused by: java.io.IOException: Socket is closed
at com.mysql.cj.protocol.AbstractSocketConnection.getMysqlInput(AbstractSocketConnection.java:72) ~[mysql-connector-java-8.0.26.jar:8.0.26]
in the writer. I am able to monitor connections on the MySql instance via workbench and everything seems fine. No stale connections (all 32 are busy 99% of the time) and if one or two do stay idle for 90 seconds hikari house keeping cleans them up as expected. I'm also able to check the MySql instance via AWS console and nothing looks out of the ordinary there either. Likewise MySql audit log shows nothing but ordinary operation at the time of the exception. I'm stumped on what is causing the socket closure. Any thoughts would be appreciated.
Datasource config...
#Configuration
public class OtlDbConfig {
#Value("${spring.datasource.otl.username}")
private String otlUser;
#Value("${spring.datasource.otl.password}")
private String otlPwd;
#Value("${spring.datasource.otl.url}")
private String otlUrl;
#Value("${spring.datasource.otl.driver-class-name}")
private String driver;
#Value("${spring.datasource.hikari.maximum-pool-size}")
private int maxPoolSize;
#Primary
#Bean(name = "OtlDataSource")
public DataSource dataSource() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setUsername(this.otlUser);
dataSource.setPassword(this.otlPwd);
dataSource.setJdbcUrl(this.otlUrl);
dataSource.setMaximumPoolSize(this.maxPoolSize);
dataSource.setMaxLifetime(90000);
dataSource.setDriverClassName(this.driver);
dataSource.setPoolName("HikariPool-OTL");
return dataSource;
}
#Primary
#Bean(name = "OtlJdbcTemplate")
public NamedParameterJdbcTemplate otlJdbcTemplate(#Qualifier("OtlDataSource") DataSource datasource) {
return new NamedParameterJdbcTemplate(datasource);
}
}
Step Config...
return stepBuilder.get("LonelyStep")
.<Statement,Statement>chunk(nonNull(chunkSize) ? chunkSize : DEFAULT_CHUNK_SIZE)
.reader(reader(null,null,null))
.writer(writer())
.listener(new ThroughputAwareChunkListener())
.taskExecutor(stepExecutor()).throttleLimit(throttleLimit)
.build();
Writer config...
public JdbcBatchItemWriter<Statement> writer() {
return new JdbcBatchItemWriterBuilder<Statement>()
.dataSource(otlDataSource)
.namedParametersJdbcTemplate(otlJdbcTemplate)
.itemPreparedStatementSetter((item, ps) -> {
ps.setLong(1, item.getXXX());
ps.setString(2, item.getYYY());
})
.sql("INSERT INTO sometable (xxx, yyy) VALUES (?,?)")
.build();
}
Executor config...
public TaskExecutor stepExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("step-worker-");
executor.setMaxPoolSize(this.maxPoolSize);
executor.setCorePoolSize(this.maxPoolSize);
return executor;
}
URL: jdbc:mysql://host:3306/db?useSSL=true&enabledTLSProtocols=TLSv1.2&autoReconnect=true
Log snippet with full stack trace...
2021-08-16 10:05:49.319 INFO 13032 --- [ step-worker-15] c.n.a.m.b.ThroughputAwareChunkListener : readCount=946400, writeCount=946400, filterCount=0, readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=9463, throughput=705.216/s
2021-08-16 10:05:49.406 INFO 13032 --- [ step-worker-14] c.n.a.m.b.ThroughputAwareChunkListener : readCount=946500, writeCount=946500, filterCount=0, readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=9465, throughput=705.291/s
2021-08-16 10:05:49.491 INFO 13032 --- [ step-worker-17] c.n.a.m.b.ThroughputAwareChunkListener : readCount=946600, writeCount=946600, filterCount=0, readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=9465, throughput=705.365/s
2021-08-16 10:05:49.538 WARN 13032 --- [ step-worker-2] com.zaxxer.hikari.pool.ProxyConnection : HikariPool-OTL - Connection com.mysql.cj.jdbc.ConnectionImpl#8a79487 marked as broken because of SQLSTATE(08S01), ErrorCode(0)
java.sql.BatchUpdateException: Communications link failure
The last packet successfully received from the server was 33 milliseconds ago. The last packet sent successfully to the server was 33 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_302]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_302]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_302]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_302]
at com.mysql.cj.util.Util.handleNewInstance(Util.java:192) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.util.Util.getInstance(Util.java:167) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.util.Util.getInstance(Util.java:174) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.exceptions.SQLError.createBatchUpdateException(SQLError.java:224) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchSerially(ClientPreparedStatement.java:853) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchInternal(ClientPreparedStatement.java:435) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.StatementImpl.executeBatch(StatementImpl.java:796) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:127) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java) [HikariCP-4.0.3.jar:na]
at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:193) [spring-batch-infrastructure-4.3.3.jar:4.3.3]
at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:186) [spring-batch-infrastructure-4.3.3.jar:4.3.3]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651) [spring-jdbc-5.3.9.jar:5.3.9]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:691) [spring-jdbc-5.3.9.jar:5.3.9]
at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:186) [spring-batch-infrastructure-4.3.3.jar:4.3.3]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) [spring-tx-5.3.9.jar:5.3.9]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) [spring-batch-core-4.3.3.jar:4.3.3]
at org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:262) [spring-batch-infrastructure-4.3.3.jar:4.3.3]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_302]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_302]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_302]
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet successfully received from the server was 33 milliseconds ago. The last packet sent successfully to the server was 33 milliseconds ago.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchSerially(ClientPreparedStatement.java:832) ~[mysql-connector-java-8.0.26.jar:8.0.26]
... 23 common frames omitted
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
The last packet successfully received from the server was 33 milliseconds ago. The last packet sent successfully to the server was 33 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_302]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_302]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_302]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_302]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.protocol.a.NativeProtocol.clearInputStream(NativeProtocol.java:791) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.protocol.a.NativeProtocol.sendCommand(NativeProtocol.java:603) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.protocol.a.NativeProtocol.sendQueryPacket(NativeProtocol.java:970) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.NativeSession.execSQL(NativeSession.java:662) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:930) ~[mysql-connector-java-8.0.26.jar:8.0.26]
... 25 common frames omitted
Caused by: java.io.IOException: Socket is closed
at com.mysql.cj.protocol.AbstractSocketConnection.getMysqlInput(AbstractSocketConnection.java:72) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.protocol.a.NativeProtocol.clearInputStream(NativeProtocol.java:787) ~[mysql-connector-java-8.0.26.jar:8.0.26]
... 29 common frames omitted
2021-08-16 10:05:49.575 INFO 13032 --- [ step-worker-18] c.n.a.m.b.ThroughputAwareChunkListener : readCount=946700, writeCount=946700, filterCount=0, readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=9466, throughput=704.914/s
2021-08-16 10:05:49.669 INFO 13032 --- [ step-worker-27] c.n.a.m.b.ThroughputAwareChunkListener : readCount=946800, writeCount=946800, filterCount=0, readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=9467, throughput=704.989/s
2021-08-16 10:05:49.762 INFO 13032 --- [ step-worker-8] c.n.a.m.b.ThroughputAwareChunkListener : readCount=946900, writeCount=946900, filterCount=0, readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=9468, throughput=705.063/s

MySQL Community 8 on macOS Catalina: can't connect to DB via JDBC

I installed MySQL Community 8.0.20 on my macOS Catalina. I'm pretty sure to have installed it correctly, since I could execute some CRUD instructions via Workbench application.
Then, I decided to write a simple Java application to access DB using JDBC. I prepared a Singleton class to get connection:
package connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionHandler
{
private static ConnectionHandler handler = null;
private static final String JDBC_URL = "jdbc:mysql://localhost:3306/";
private static final String DATABASE = "javaTest";
private static final String DATABASE_ID = "root";
private static final String DATABASE_PW = "root_password";
private ConnectionHandler() {}
public synchronized static ConnectionHandler getInstance()
{
if(handler == null)
handler = new ConnectionHandler();
return handler;
}
public Connection getConnection() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException
{
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
// Connection conn = DriverManager.getConnection(JDBC_URL + DATABASE, DATABASE_ID, DATABASE_PW);
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/javaTest", "root", "root_password");
return conn;
}
}
If I execute application in debug mode, I can verify that it gets to penultimate instruction in method getConnection(), then after about 15 seconds the following exception is returned:
Exception in thread "main" com.mysql.cj.jdbc.exceptions.CommunicationsException: 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 com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at connection.ConnectionHandler.getConnection(ConnectionHandler.java:30)
at dao.JDBCExampleDAOImpl.findCustomerById(JDBCExampleDAOImpl.java:16)
at test.JDBCExampleTest.main(JDBCExampleTest.java:13)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: 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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:338)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1340)
at com.mysql.cj.NativeSession.connect(NativeSession.java:157)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
... 8 more
Caused by: javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)
at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:565)
at sun.security.ssl.InputRecord.read(InputRecord.java:529)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:336)
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:329)
... 15 more
On the other hand, executing without debug I get the following:
Exception in thread "main" java.sql.SQLException: The server time zone value 'CEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at connection.ConnectionHandler.getConnection(ConnectionHandler.java:30)
at dao.JDBCExampleDAOImpl.findCustomerById(JDBCExampleDAOImpl.java:16)
at test.JDBCExampleTest.main(JDBCExampleTest.java:13)
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'CEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2118)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2142)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
... 8 more
MySQL is on and I closed Workbench, in case it could create conflicts.
Can you spot the problem?
Thanks for support.

AWS RDS How to set up a MySQL Database

I have a Java application running on successfully on Amazon Web Services Elastic Beanstalk.
I am trying to set up MySQL. I have created a DB Instance as you can see:
Question 1:
How do I connect my Java App to the Database?
I have the following code (after viewing this):
#Bean
public DataSource dataSource() {
// Openshift
// String host = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
// String port = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
// String username = System.getenv("OPENSHIFT_MYSQL_DB_USERNAME");
// String password = System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD");
// AWS
String host = System.getenv("RDS_HOSTNAME");
String port = System.getenv("RDS_PORT");
String username = System.getenv("RDS_USERNAME");
String password = System.getenv("RDS_PASSWORD");
String dbname = System.getenv("RDS_DB_NAME");
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
if (host == null) {
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
} else {
//dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/");
// Openshift
//dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + environment.getRequiredProperty("jdbc.dbname"));
// AWS
dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + dbname);
dataSource.setUsername(username);
dataSource.setPassword(password);
System.out.println("jdbc:mysql://" + host + ":" + port + "/" + dbname+", username: "+username+", password: "+password);
}
return dataSource;
}
(p.s. the commented out code works on OpenShifts server)
But I get the following:
org.springframework.web.util.NestedServletException: Request
processing failed; nested exception is
org.springframework.transaction.CannotCreateTransactionException:
Could not open JPA EntityManager for transaction; nested exception is
org.hibernate.exception.JDBCConnectionException: Unable to acquire
JDBC Connection
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
Question 2:
From an existing database, in MySQL Workbench, I have exported sql scripts to create a schema and tables, and then populate them. How do I import this into the AWS RDS MySQL database?
More info:
Server Logs:
-------------------------------------
/var/log/tomcat8/localhost.2017-02-21.log
-------------------------------------
21-Feb-2017 14:42:51.133 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath
21-Feb-2017 14:42:51.737 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'rest'
21-Feb-2017 14:57:36.680 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [rest] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection] with root cause
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:244)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2504)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2323)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:99)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:129)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:247)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:254)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:203)
at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:56)
at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:67)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:427)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy55.findAll(Unknown Source)
at com.jobs.spring.controller.CategoryRESTService.findAllCategorys(CategoryRESTService.java:31)
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:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:676)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
21-Feb-2017 15:09:21.090 INFO [localhost-startStop-2] org.apache.catalina.core.ApplicationContext.log Destroying Spring FrameworkServlet 'rest'
21-Feb-2017 15:09:38.729 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath
21-Feb-2017 15:09:39.329 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'rest'
UPDATE
I also added rules to open it for everyone, but still get the same error:
The problem has to do with your database and the security group.
Hover to the "i" icon next to the Cluster Endpoint.
A popup will appear with the security groups.
Hit the first default link and you will be redirected to the security groups configuration.
Then you have to edit the security group and add an inbound rule in order to include your local ip.
Keep in mind that this will work only if your rds is on a public subnet.
This link is pretty helpful for troubleshooting.
More information on security groups

MariaDB CommunicationsException: Communications link failure

There seems to be enough of questions relating to CommunicationsException were posted on Stackoverflow. But none of them helps me out of a difficult position.
I installed MariaDB 5.5 in my CentOS 7 server, and configured everything so that I can connect to the DB server remotely through a MySQL Workbench or Data Source Explorer in eclipse. A screen capture of the succeed connections is like below.
However, when I try to connect the DB Server via JDBC, it continues to fail with the Exception "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure".
The test class is shown as following.
package com.pratice;
import java.sql.*;
public class DatabaseConn {
public static void main(String[] args) throws Exception{
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String url = "jdbc:mysql://59.12.140.121:6330/myPrjs";//?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
String username = "user";
String password = "password";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT 1");
while(rs.next()){
System.out.print(rs.getObject(1) + "\t" + rs.getObject(2));
}
}finally{
if(rs!=null) {
rs.close();
}
if(stmt!=null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
}
}
When I run DatabaseConn, I got the error messages.
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2539)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.webjsp.pratice.DatabaseConn.main(DatabaseConn.java:18)
Caused by: java.net.SocketException: Bad address: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 15 more
I cannot solve this problem so I searched on the internet, and I found a checklist at here . But now that I can connect to my DB server via IDEs, I don't know what could be wrong.
I also tried to use org.mariadb.jdbc.driver instead of mysql driver, I got error messages too.
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Could not connect to 59.12.140.121:6330 : Bad address: connect
at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
at org.mariadb.jdbc.Driver.connect(Driver.java:115)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DatabaseConn.main(DatabaseConn.java:16)
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not connect to 59.12.140.121:6330
: Bad address: connect
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:714)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.<init>(MySQLProtocol.java:280)
at org.mariadb.jdbc.Driver.connect(Driver.java:111)
... 3 more
Caused by: java.net.SocketException: Bad address: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:387)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:709)
... 5 more
Could anyone tell me how can I solve this problem, or give me some hints that why does it happening? Thank you so much.
The key point to figure the problem out is at "java.net.SocketException: Bad address: connect".
The problem was caused by firewall rules at the client side (My Windows PC). I enabled Ahnlab V3 Internet Security Personal Firewall on my client PC. The outbound rules only allow certain types of outgoing socket by default. When I tried to connect to my remote server with a workbench, there was no problem. But when I tried to connect to the server by running the java Class, the local firewall kept the socket, so the connection requests did not even go through my network card! I add a new outbound rule which allows mysql outbound connection, and then my program runs normally.
Hope this will help anyone who encounters the same problem.

Exception while dropping database in JavaFX

private void delete() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/delete?"
+ "user=root&password=virus");
statement = connect.createStatement();
preparedStatement = connect
.prepareStatement("DROP DATABASE delete");
preparedStatement.executeUpdate();
preparedStatement = connect
.prepareStatement("CREATE DATABASE delete");
preparedStatement.executeUpdate();
}
This is my code to delete a database in javafx. But when i ran this code it gives me an exception. Is details are -
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at deleteaccount.DeleteAccount.delete(DeleteAccount.java:106)
at deleteaccount.DeleteAccount.access$000(DeleteAccount.java:26)
at deleteaccount.DeleteAccount$1.handle(DeleteAccount.java:86)
at deleteaccount.DeleteAccount$1.handle(DeleteAccount.java:82)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
Why this exception occur ? How can I solve it ?