I just created a free MongoDB atlas cluster instance. But somehow I am failing to connect it from my application as well as from the MongoDB Compas.
I get below error when I try to run my application.
Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=experimental-1-epdri.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: experimental-1-epdri.mongodb.net}, caused by {java.net.UnknownHostException: experimental-1-epdri.mongodb.net}}]
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:377) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:411) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:144) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:71) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.Mongo.execute(Mongo.java:845) ~[mongodb-driver-3.4.2.jar:na]
at com.mongodb.Mongo$2.execute(Mongo.java:828) ~[mongodb-driver-3.4.2.jar:na]
at com.mongodb.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:491) ~[mongodb-driver-3.4.2.jar:na]
at com.mongodb.MongoCollectionImpl.createIndex(MongoCollectionImpl.java:458) ~[mongodb-driver-3.4.2.jar:na]
at org.axonframework.mongo.eventsourcing.eventstore.AbstractMongoEventStorageStrategy.ensureIndexes(AbstractMongoEventStorageStrategy.java:201) ~[axon-mongo-3.0.5.jar:3.0.5]
at org.axonframework.mongo.eventsourcing.eventstore.MongoEventStorageEngine.ensureIndexes(MongoEventStorageEngine.java:123) ~[axon-mongo-3.0.5.jar:3.0.5]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
... 76 common frames omitted
Process finished with exit code 1
On Compas it simply says MongoDB instance isn't running at this place. I have checked my cluster and I see below.
But still I can't connect to mongo cluster. Further more I tried with `Mongo CLI as well where I found error as shown below.
Below is the connection string that I get from the MongoDB atlas page.
mongodb+srv://admin_eventdb:<PASSWORD>#experimental-1-epdri.mongodb.net/test?retryWrites=true
Please help solve this.
Please try with:
Hostname: experimental-1-epdri.mongodb.net
SRV Record: checked
Authentication: Username / Password
Username: admin_eventdb
Password: <PASSWORD>
Authentication Database: admin
Replica Set Name:
Read Preference: Primary
SSL: System CA / Atlas Deployment
SSL Tunnel: None
I had the same issue. Via connection string using Java Driver 3.4 it would be:
mongodb://user:<PASSWORD>#cluster0-shard-00-00-ox90k.mongodb.net:27017,cluster0-shard-00-01-ox90k.mongodb.net:27017,cluster0-shard-00-02-ox90k.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
Instead of <PASSWORD> I wrote own password. admin1is my admin-user.
Updated: if you want to use drivers 3.7+, you need to write instead of format connection (and to avoid my issues above)
MongoClientURI uri = new MongoClientURI("mongodb+srv://admin:mypassword#cluster0-ox90k.mongodb.net/test?retryWrites=true");
MongoClient mongoClient = new MongoClient(uri);
another variant using MongoClients.create() (as of the 3.7 release),:
MongoClient mongoClient = MongoClients.create("mongodb+srv://admin:mypassword#cluster0-ox90k.mongodb.net/test?retryWrites=true");
Note: the password need to write not like mongodb://user:<mypassword>#..., just in format mongodb://user:mypassword#... without braces <>.
I point I mentioned
Please login to mongodb atlas
1.go to security section
2.network access
Then allow anywhere access that it's may be helps.
for Node.js : checkout Atlas MongoDB connection
const mongoose = require('mongoose');
const conStr = 'mongodb+srv://lord:<password>#cluster5-eeev8.mongodb.net/test?retryWrites=true&w=majority'
const DB = conStr.replace(
'<password>',
myPass
);
const DB = conStr.replace(
'test',
myDatabaseName
);
//remember mongoose.connect() return promise
mongoose
.connect(DB, {
usedNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then((con) => {
console.log(con.connection);
console.log('DB connection successful');
});
Just tried to use Atlas. This is the configuration that worked for me with Spring Boot 2.3.1.RELEASE
spring:
data:
mongodb:
database: sample_training
uri: mongodb+srv://<user>:<pass>#cluster0-hosturl.aws|gcp.mongodb.net/?retryWrites=true&w=majority
Related
I am completely new to Wildfly/JBoss so i am clueless what to do, i am sitting on this problem since yesterday noon.
I am trying to use the mysql-connector-java-8.0.20.jar as the connector and my Wildfly version is wildfly-19.0.0.Final.
So the deployment on the server seemed to work fine, but whenever i try to add the datasource and test the connection i am getting this error:
"WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid"
log/ Server throws:
2020-06-19 12:47:04,231 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) WFLYJCA0001: Bound data source [java:jboss/datasources/MySqlDS]
2020-06-19 12:47:04,353 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (External Management Request Threads -- 1) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
at org.jboss.ironjacamar.jdbcadapters#1.4.20.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)
at org.jboss.ironjacamar.jdbcadapters#1.4.20.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)
at org.jboss.ironjacamar.jdbcadapters#1.4.20.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)
at org.jboss.ironjacamar.impl#1.4.20.Final//org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1326)
at org.jboss.ironjacamar.impl#1.4.20.Final//org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:499)
at org.jboss.ironjacamar.impl#1.4.20.Final//org.jboss.jca.core.connectionmanager.pool.AbstractPool.internalTestConnection(AbstractPool.java:1067)
at org.jboss.ironjacamar.impl#1.4.20.Final//org.jboss.jca.core.connectionmanager.pool.strategy.OnePool.testConnection(OnePool.java:93)
at org.jboss.as.connector#19.0.0.Final//org.jboss.as.connector.subsystems.common.pool.PoolOperations$TestConnectionInPool.invokeCommandOn(PoolOperations.java:240)
at org.jboss.as.connector#19.0.0.Final//org.jboss.as.connector.subsystems.common.pool.PoolOperations$1.execute(PoolOperations.java:97)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:999)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:743)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:467)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1413)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:429)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.ModelControllerImpl.lambda$execute$1(ModelControllerImpl.java:246)
at org.wildfly.security.elytron-private#1.11.2.Final//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:289)
at org.wildfly.security.elytron-private#1.11.2.Final//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:255)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:246)
at org.jboss.as.domain-http-interface#11.0.0.Final//org.jboss.as.domain.http.server.DomainApiHandler.handleRequest(DomainApiHandler.java:212)
at io.undertow.core#2.0.30.Final//io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72)
at org.jboss.as.domain-http-interface#11.0.0.Final//org.jboss.as.domain.http.server.DomainApiCheckHandler.handleRequest(DomainApiCheckHandler.java:93)
at org.jboss.as.domain-http-interface#11.0.0.Final//org.jboss.as.domain.http.server.security.ElytronIdentityHandler.lambda$handleRequest$0(ElytronIdentityHandler.java:62)
at org.wildfly.security.elytron-private#1.11.2.Final//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:313)
at org.wildfly.security.elytron-private#1.11.2.Final//org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:270)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:254)
at org.jboss.as.controller#11.0.0.Final//org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:225)
at org.jboss.as.domain-http-interface#11.0.0.Final//org.jboss.as.domain.http.server.security.ElytronIdentityHandler.handleRequest(ElytronIdentityHandler.java:61)
at io.undertow.core#2.0.30.Final//io.undertow.server.handlers.BlockingHandler.handleRequest(BlockingHandler.java:56)
at io.undertow.core#2.0.30.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:376)
at io.undertow.core#2.0.30.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:835)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.sql.SQLException: The server time zone value 'Mitteleurop?ische Sommerzeit' 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 deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at org.jboss.ironjacamar.jdbcadapters#1.4.20.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
... 35 more
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Mitteleurop?ische Sommerzeit' 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 java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2120)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2143)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)
at deployment.mysql-connector-java-8.0.20.jar//com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
... 39 more
2020-06-19 12:47:04,356 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 1) WFLYCTL0013: Operation ("test-connection-in-pool") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MySqlDS")
]) - failure description: "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid"
As i said, i an new, so please dont expect to much existing knowledge about wildfly.
Thanks in regards!
Solution 1: Pass the timeZone using the database url on the connector
Your database url should look like jdbc:mysql://ip_address:port/port?serverTimezone=UTC
You can change to your timezone of choice
Solution 2: Change your MySQL configuration file
On ubuntu the configuration file is my.cnf. For ubuntu 18.04 the file's location is /etc/mysql/my.cnf
Add a line as below:
default-time-zone = '+01:00'
Set to your preferred time zone
Restart your MySQL server.
Yes thanks, solution 2 worked!
In my case the my.cnf-File was called "my", so that was kinda confusing. I dont know, why it is called like that.
I found the file at this path:
C:\ProgramData\MySQL\MySQL Server 8.0
I'm trying to establish Oracle DB connection from the application which runs on an EC2 instance of AWS. Oracle DB is in on-prem server. Firewall has been opened and I'm able to telnet to the SCAN and VIP hosts of that DB from my EC2 instance. But, still I'm getting the below exception:
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:392) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:434) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:687) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:343) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
... 239 common frames omitted
Caused by: java.net.UnknownHostException: <<hostname>>: unknown error
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_40-internal]
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAllByName0(InetAddress.java:1255) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAllByName(InetAddress.java:1171) ~[na:1.8.0_40-internal]
at java.net.InetAddress.getAllByName(InetAddress.java:1105) ~[na:1.8.0_40-internal]
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:117) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.nt.ConnOption.connect(ConnOption.java:133) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:370) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
JDBC URL:
jdbc:oracle:thin:#(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)
(HOST = <<IP address of the host>>)(PORT = 1590)))(LOAD_BALANCE = yes)
(CONNECT_DATA =(SERVICE_NAME = <<example.service.com>>)(FAILOVER_MODE =(TYPE = SELECT)
(METHOD = BASIC))))`
Are you using java 8 ? If so then probably it's related to this bug
Java 7 or 9 would probably give you a more useful error message instead of "unknown error" (eg possibly "Name or service not known")
Apart from that, did you try a tnsping from the host you're trying to connect from ?
Also as per the below in the Oracle driver documentation when using a tnsnames entry in the jdbc URL it should be as below, using OCI driver :
Note that you can also specify the database by a TNSNAMES entry. You can find the available TNSNAMES entries listed in the file tnsnames.ora on the client computer from which you are connecting. For example, if you want to connect to the database on host myhost as user scott with password tiger that has a TNSNAMES entry of MyHostString, enter:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:#MyHostString","scott","tiger");
I would like to start my Java/Play! Service even though the Database is not yet reachable. So far, if the database is not available the service stops. Is it possible in Play to try and reconnect every second or so without completely stopping the service and reconnecting to db as soon as connection is available.
Our application.conf currently looks like this:
play.evolutions.enabled=false
//play.db.pool=bonecp
db {
default.driver=org.postgresql.Driver
default.url="jdbc:postgresql://postgresdb.postgres:5432/postcode"
default.username="<username>"
default.password="<strong-password>"
}
play.db {
config = "db"
prototype.hikaricp = {
connectionTimeout = 250 milliseconds
initializationFailFast = false
readOnly = true
}
}
ebean.default = ["models.*"]
Currently I get the following logs:
2017-05-15 13:26:54.525 [error] postcode-play: Connection error:
org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections
Ort: Datei: postinit.c, Routine: InitPostgres, Zeile: 779.
Server SQLState: 53300
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2538)
at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:122)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:227)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:431)
at org.postgresql.Driver.connect(Driver.java:247)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101)
2017-05-15 13:26:54.626 [error] postcode-play: Connection error:
org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections
Ort: Datei: postinit.c, Routine: InitPostgres, Zeile: 779.
Server SQLState: 53300
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2538)
at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:122)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:227)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:431)
at org.postgresql.Driver.connect(Driver.java:247)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101)
.
.
.
Indicating that the server does not stop altogether but tries to connect to db multiple times which is as desired. But if the database becomes available the following logs are written:
2017-05-15 14:08:43.748 [error] postcode-play:
! #7430ed7gf - Internal server error, for (GET) [/?postcode=88682&country=DE] ->
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.configError(Configuration.scala:155)
at play.api.Configuration.reportError(Configuration.scala:808)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
at scala.collection.immutable.List.foreach(List.scala:392)
at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
at play.api.db.DBApiProvider.get(DBModule.scala:62)
at play.api.db.DBApiProvider.get(DBModule.scala:58)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
Caused by: java.sql.SQLTransientConnectionException: HikariPool-4 - Connection is not available, request timed out after 5001ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:548)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:83)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:138)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
at scala.collection.immutable.List.foreach(List.scala:392)
at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:265)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:431)
at org.postgresql.Driver.connect(Driver.java:247)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:341)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:193)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:430)
Caused by: java.net.ConnectException: Verbindungsaufbau abgelehnt (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 org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194
)
The server cannot reach out to the database even though it is available now. If I restart the server the database will be found and can be worked with, but the database lways has to be there on startup. How can I fix that, so that the app can be started independently of the database?
If the database becomes unavailable after the application has started it is no problem after the db becomes available again. it is automatically reconnected.
Any help is greatly apreciated!
It seems like you are leaving some connections open to Postgres. These connections must be closed or else Postgres will hit its max_connections limit.
You could increase max_connections but it's not recommended as performance of Postgres will degrade if it's set too high. Also, as you are using HikariCP it wouldn't be a bad idea to take a look at the HikariCP docs, in particular the idleTimeout and the minimumIdle config variables should help you.
If the above doesn't work then you must confirm exactly how many connections are being made to Postgres. Maybe even check the number of sessions you personally are making to Postgres via SSH or through other apps, not just the number of Play Framework connections.
I tried to connect to my remote MySQL database, but I failed and got this error.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The confusion is that It was effective when I used MySQL-Front tool to connect the remote database, and I can ping to the IP address successfully. but when I used my code, it wound show the error after about ten seconds.
Also when I used the wrong username or password in my code, it wound show the wrong verification immediately. Did that prove it is no problem to set up conection?
Here is my code(It can work on my localhost database):
public static void main(String[] args) {
String url = "jdbc:mysql://(IP address):3306/";
String dbName = "talk";
String driver = "com.mysql.jdbc.Driver";
String userName = "talkroot";
String password = "123456";
try {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url + dbName,
userName, password);
System.out.println("connect");
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("end");
}
Here is the error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2120)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.test.TestMySQL.main(TestMySQL.java:16)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 21298 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3009)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2895)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3438)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1802)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3444)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2062)
... 12 more
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2452)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2906)
... 20 more
Anyone can help me please?
This com.mysql.jdbc.exceptions.jdbc4.CommunicationsException exception occurs if your database connection is idle for long time. This idle connection returns true on connection.isClosed(); but if we try to execute statement then it will fire this exception so I will suggest to go with database pooling.
Usually this error occurs when you don't use right port number. May be the machine which working on this database (client'db) has different port number. (Ex: 3307) . Go task manager==> Services ==> services and check is there other version of mysql. if they use 3306 change your port to 3307.
you can try to replace the mysql-connector-java-version.jar jar file. Some people update the jar file from 5.1.10 to 5.1.14, then it works. Wish you are luck..
update your drive version to:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
Double Check the following things:
Verify whether the IP address/Port Number is correct or not
Ping to the server using ping "IP address" it may tells is the server in startup mode/shutdown mode
If you are getting connection objects from connection pool, verify
once connections availability.
Hope this information helps...
I solved it by removing the port number from the connection URL.
So instead of using connection string as:
jdbc:mysql://12x.xxx.xxx.xxx:1527/yourdbname
use
jdbc:mysql://12x.xxx.xxx.xxx/yourdbname
Also when I used the wrong username or password in my code, it wound show the wrong verification immediately. Did that prove it is no problem to set up conection?
this is probably done locally. so it doesn't relate to why your code isn't working.
There seems to be many ways to go about this, so you can try multiple things; people have solved this link failure in different ways as per their own situations:
Here are some the solutions:
changing "bind-address" attribute
Uncomment "bind-address" attribute or change it to one of the following IPs:
bind-address="127.0.0.1"
or
bind-address="0.0.0.0"
commenting out "skip-networking"
If there is a "skip-networking" line in your MySQL config file, make it comment by adding "#" sign at the beginning of that line.
change "wait_timeout" and "interactive_timeout"
Add these lines to the MySQL config file:
[wait_timeout][1] = number
interactive_timeout = number
connect_timeout = number
check Operating System proxy settings
Make sure the Fire wall, or Anti virus soft wares don't block MySQL service.
change connection string
Check your query string. your connection string should be some thing like this:
dbName = "my_database";
dbUserName = "root";
dbPassword = "";
String connectionString = "jdbc:mysql://localhost/" + dbName + "?user=" + dbUserName + "&password=" + dbPassword + "&useUnicode=true&characterEncoding=UTF-8";
Make sure you don't have spaces in your string. All the connection string should be continues without any space characters.
Try to replace "localhost" with your port, like 127.0.0.1.
Also try to add port number to your connection string, like:
String connectionString = "jdbc:mysql://localhost:3306/my_database?user=root&password=Pass&useUnicode=true&characterEncoding=UTF-8";
Usually default port for MySQL is 3306.
Don't forget to change username and password to the username and password of your MySQL server.
update your JDK driver library file
test different JDK and JREs (like JDK 6 and 7)
don't change max_allowed_packet
"[max_allowed_packet][4]" is a variable in MySQL config file that indicates the maximum packet size, not the maximum number of packets. So it will not help to solve this error.
change tomcat security
change TOMCAT6_SECURITY=yes to TOMCAT6_SECURITY=no
use validationQuery property
use validationQuery="select now()" to make sure each query has responses
AutoReconnect
Add this code to your connection string:
&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
Your MySQL server isn't running. Check the same in the services page of the task manager if you are running Windows.
If you are working with Amazon Ubuntu instance then you have to follow this steps:
Check the amazon instance
Check the security group of instance
Assign the mysql/aura service and add your machine ip here or
service provider ip.
Please update your mysql configuration file in /etc/mysql/my.cnf file
By default, MySQL only allows connections from the localhost address. The configuration file is usually found in /etc/mysql/my.cnf
You will want to comment out the bind-address line by making it look like this:
#bind-address = 127.0.0.1
Next, you will need to restart the database server:
sudo /etc/init.d/mysql restart
I had faced this issue and struggled a lot like a lot. I did everything single thing said in all the portals and not worked for me. The only thing which worked to me was updating my jar file to the current new version . Earlier I was using 5.1.38 and now updated to 8.0.15 and just that my program worked super fine.
I'm running the following tutorial:
http://download.oracle.com/javase/6/docs/technotes/guides/security/jgss/tutorials/BasicClientServer.html
I'm getting the following prompts:
Connected to server localhost/127.0.0.1
Kerberos username [login]: {I enter my username here}
Kerberos password for login: {I enter my password here}
I get the following error:
Can you ascertain the root cause of this?
Exception in thread "main" GSSException: No valid credentials provided (Mechanism level: Attempt to obtain new INITIATE credentials failed! (null))
at sun.security.jgss.krb5.Krb5InitCredential.getTgt(Krb5InitCredential.java:333)
at sun.security.jgss.krb5.Krb5InitCredential.getInstance(Krb5InitCredential.java:128)
at sun.security.jgss.krb5.Krb5MechFactory.getCredentialElement(Krb5MechFactory.java:106)
at sun.security.jgss.krb5.Krb5MechFactory.getMechanismContext(Krb5MechFactory.java:172)
at sun.security.jgss.GSSManagerImpl.getMechanismContext(GSSManagerImpl.java:209)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:195)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:162)
at demo.SampleClient.main(SampleClient.java:145)
Caused by: javax.security.auth.login.LoginException: Message stream modified (41)
at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:696)
at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:542)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
at javax.security.auth.login.LoginContext$5.run(LoginContext.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokeCreatorPriv(LoginContext.java:703)
at javax.security.auth.login.LoginContext.login(LoginContext.java:575)
at sun.security.jgss.GSSUtil.login(GSSUtil.java:246)
at sun.security.jgss.krb5.Krb5Util.getTicket(Krb5Util.java:136)
at sun.security.jgss.krb5.Krb5InitCredential$1.run(Krb5InitCredential.java:328)
at java.security.AccessController.doPrivileged(Native Method)
at sun.security.jgss.krb5.Krb5InitCredential.getTgt(Krb5InitCredential.java:325)
... 7 more
Caused by: KrbException: Message stream modified (41)
at sun.security.krb5.KrbKdcRep.check(KrbKdcRep.java:53)
at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:96)
at sun.security.krb5.KrbAsReq.getReply(KrbAsReq.java:449)
at sun.security.krb5.Credentials.sendASRequest(Credentials.java:410)
at sun.security.krb5.Credentials.acquireTGT(Credentials.java:378)
at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:662)
... 23 more
I got exceptions “Message stream modified (41)”, when the Kerberos realm didn’t match. The realm (in system property java.security.krb5.realm) has to match exactly, including upper/lower case.
I'm wondering if this is a possibility (ie even if registry key is set, locked out for local administrators):
http://cr.openjdk.java.net/~weijun/special/krb5winguide-2/raw_files/new/kwin
Known Issues
If an AD account is also added into local administrator group on the
client PC, Microsoft restricts such client from getting the session key
for tickets (even if you set the allowtgtsessionkey registry key to 1).
The workaround is: Just forget you're a logged in user, call kinit.exe.
Do not depends on LSA credential cache.
I cannot confirm that issue. I do have admin rights on my machine and still are able to obtain the session key from the LSA. You should enable full debug ouput on JGSS and the Krb5LoginModule. Share your krb5.ini and login.conf too. I hope your are aware that the above example cannot work because your client cannot obtain a ticket for a local host. It has to be a FQDN with an appropriate SPN set in the Active Directory.