I am trying to connect to a MySQL database so I will reverse engineer the tables into classes on a Spring Boot Project. When I enter the properties and , after adding the jar file, and trying to test the connection it says Ping failed!
Selecting Database perspective through STS
Trying to create you database connection
Connection profile with properties
The jar
Testing the connection
The exception
java.lang.ClassNotFoundException: Generic JDBC
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:814)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:327)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:96)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnectionFactory.createConnection(JDBCConnectionFactory.java:53)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Driver name should be com.mysql.jdbc.Driver
Related
I am trying to connect to my DocumentNodeStore in a postgresql database.
Following the instruction from here https://jackrabbit.apache.org/oak/docs/features/oak-run-nodestore-connection-options.html
export CLASSPATH=postgresql-42.2.5.jar:oak-run-1.9.9.jar
java org.apache.jackrabbit.oak.run.Main console jdbc:postgresql://localhost/mydb --rdbjdbcuser myuser --rdbjdbcpasswd mypassword
I am getting the following error:
Apache Jackrabbit Oak 1.9.9
Exception in thread "main" org.apache.jackrabbit.oak.plugins.document.DocumentStoreException: trying to create datasource org.apache.tomcat.jdbc.pool.DataSource
at org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory.forJdbcUrl(RDBDataSourceFactory.java:90)
at org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory.forJdbcUrl(RDBDataSourceFactory.java:100)
at org.apache.jackrabbit.oak.run.cli.DocumentFixtureProvider.configureDocumentMk(DocumentFixtureProvider.java:117)
at org.apache.jackrabbit.oak.run.cli.NodeStoreFixtureProvider.create(NodeStoreFixtureProvider.java:70)
at org.apache.jackrabbit.oak.run.cli.NodeStoreFixtureProvider.create(NodeStoreFixtureProvider.java:49)
at org.apache.jackrabbit.oak.console.Console.main(Console.java:49)
at org.apache.jackrabbit.oak.run.ConsoleCommand.execute(ConsoleCommand.java:27)
at org.apache.jackrabbit.oak.run.Main.main(Main.java:49)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSource
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory.forJdbcUrl(RDBDataSourceFactory.java:74)
... 7 more
Am I missing anything?
As mentioned in the link:
Note that the oak-run JAR file lacks several RDB specific JAR files that need to be added to the classpath:
1. tomcat-jdbc-8.5.*.jar (Apache Tomcat JDBC connection pool)
2. juli-6.0.*.jar (Apache Tomcat Logger)
3. Whatever JDBC driver is needed to connect to the database
I missed out the first 2 jars
After build the native image I've the following error
I'm using a H2 database in file mode.
Do I should understand that it's not possible to use H2 in native mode using a file DB ?
./controler-1.0-SNAPSHOT-runner -Dquarkus.datasource.url=jdbc:h2:~/Dev/controler/sic
quarkus.datasource.url=jdbc:h2:./sic
quarkus.datasource.driver=org.h2.Driver
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1538)
at org.hibernate.query.Query.getResultList(Query.java:165)
at com.evolis.rpms.sic.controler.StatusBean.checkHostersState(StatusBean.java:100)
at com.evolis.rpms.sic.controler.StatusBean_Subclass.checkHostersState$$superaccessor6(Unknown Source)
at com.evolis.rpms.sic.controler.StatusBean_Subclass$$function$$12.apply(Unknown Source)
at io.quarkus.arc.InvocationContextImpl.interceptorChainCompleted(InvocationContextImpl.java:141)
at io.quarkus.arc.InvocationContextImpl.proceed(InvocationContextImpl.java:161)
at io.quarkus.arc.ActivateRequestContextInterceptor.aroundInvoke(ActivateRequestContextInterceptor.java:22)
at io.quarkus.arc.ActivateRequestContextInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.InvocationContextImpl$InterceptorInvocation.invoke(InvocationContextImpl.java:254)
at io.quarkus.arc.InvocationContextImpl.invokeNext(InvocationContextImpl.java:133)
at io.quarkus.arc.InvocationContextImpl.proceed(InvocationContextImpl.java:157)
at com.evolis.rpms.sic.controler.StatusBean_Subclass.checkHostersState(Unknown Source)
at com.evolis.rpms.sic.controler.StatusBean_ClientProxy.checkHostersState(Unknown Source)
at com.evolis.rpms.sic.controler.StatusBean_ScheduledInvoker_checkHostersState_68e943c3d502cee246226dbe51d54e7cd7502168.invoke(Unknown Source)
at io.quarkus.scheduler.runtime.QuartzScheduler$InvokerJob.execute(QuartzScheduler.java:249)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 3 more
Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:109)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1988)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1918)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1896)
at org.hibernate.loader.Loader.doQuery(Loader.java:936)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:339)
at org.hibernate.loader.Loader.doList(Loader.java:2693)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2540)
at org.hibernate.loader.Loader.list(Loader.java:2502)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1537)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1561)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529)
... 19 more
Caused by: org.h2.jdbc.JdbcSQLException: General error: "java.lang.UnsupportedOperationException: H2 database compiled into a native-image is only functional as a client: can't create an Embedded Database Session" [50000-197]
at org.h2.message.TraceObject.logAndConvert(TraceObject.java:357)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:140)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:103)
at org.h2.Driver.connect(Driver.java:69)
at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:200)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:357)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:346)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
... 2 more
Caused by: java.lang.UnsupportedOperationException: H2 database compiled into a native-image is only functional as a client: can't create an Embedded Database Session
at org.h2.engine.ConnectionInfo.isRemote(ConnectionInfo.java:20)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:331)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:124)
... 12 more
Yes, at least for now, we don't support running H2 as a server in native mode. The only thing we support is connecting to a remote H2 database using the H2 JDBC client.
It didn't seem like time well spent at the time and, to be honest, I'm not sure we ever will.
If you're interested, feel free to try to get it working but it might not be easy.
This is now supported in quarkus.
If you want to run integration tests in native executable, you can add #QuarkusTestResource(H2DatabaseTestResource.class) on any class in your integration tests. The test suite will start and stop the embedded database as a separate process as necessary to run your tests.
Example,
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.h2.H2DatabaseTestResource;
#QuarkusTestResource(H2DatabaseTestResource.class)
public class TestResources {}
This allows you to test your application even when it is compiled into a native executable, while the database will run in the JVM as usual.
Connect to it using:
quarkus.datasource.db-kind=h2
quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test
I'm building a java server program that connects to a psql database with JDBC drivers. I need to compile the program in a .jar file, but when I try to do so and run it, I get this exception. (the program has to run on a linux machine)
java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at Server.connectToDatabase(Server.java:53)
at Server.(Server.java:33)
at Main.main(Main.java:10)
Since the program works fine on IntelliJ editor, I assume that the problem is that there isn't the jdbc driver in the jar file. How can I add it?
You need add PostgreDriver to your classpath and use command like following.
$Java -classpath postgre-jar+additional-jars-if-any Your-Main-class
I'm working on IntelliJ with Tomcat and postgresql but I have this problem when I run my application:
java.lang.ClassNotFoundException: org.postgres.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264) and so on..
I have already put the JAR file in tomcat/lib but nothing changed.
Thanks for helping me.
You misspelled/shortened the qualified name of the PostgreSQL JDBC driver. The correct name is
org.postgresql.Driver
Make sure JDBC jar is added to the module dependencies: http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html.
I have the following exception when running Java app for MongoDB:
[localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017 while accessing MongoDB with Java
Call stack is follows:
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.0.4.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114) ~[mongodb-driver-core-3.0.4.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127) ~[mongodb-driver-core-3.0.4.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_45]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_45]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) ~[na:1.8.0_45]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_45]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_45]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_45]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_45]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_45]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50) ~[mongodb-driver-core-3.0.4.jar:na]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongodb-driver-core-3.0.4.jar:na]
... 3 common frames omitted
Neither of these names belong to my application. Also I have NO MONGODB server on local host. I am using remote host and setting it later. An exception occurs BEFORE any of my statements concerning Mongo.
UPDATE
This is probably some Spring provided beans accessing Mongo. How to disable them?
My config contains following dependencies:
dependencies {
compile('javax.media:jai_core:1.1.3')
//compile('jai_core:1.1.3')
// compile('org.springframework.boot:spring-boot-starter-data-mongodb')
compile('org.mongodb:mongodb-driver:3.0.4')
compile('org.mongodb:bson:3.0.4')
compile('org.geotools:gt-api:14.2')
compile('org.geotools:gt-shapefile:14.2')
compile('org.geotools:gt-geometry:14.2')
compile('org.geotools:gt-referencing:14.2')
compile('org.geotools:gt-geojson:14.2')
compile('org.geotools:gt-mongodb:14.2')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
i.e. I have removed org.springframework.boot:spring-boot-starter-data-mongodb and was thinking will use Mongo myself...
UPDATE2
I found related question: How to disable spring-data-mongodb autoconfiguration in spring-boot
I was to add exclusion annotation to my main annotated class,
i.e. instead of
#SpringBootApplication
I should have
#SpringBootApplication
#EnableAutoConfiguration(exclude={MongoAutoConfiguration.class})
Try adding
spring.data.mongodb.host=hostIpOnWhichMongoIsRunning
spring.data.mongodb.port=27017
into application.properties.
If Mongo is not running on localhost, this should fix the issue.
My IDEA suggested that I do this.
#SpringBootApplication(exclude = {MongoAutoConfiguration.class})
I can't say for sure. It's kind of not enough information question.
I can say that: Mongo driver by default tries to connect to the local host.
Probably you haven't specified the Mongo host/port.
So you'll have to configure the MongoDB host/port/credentials (if you have those).
Maybe it's network related issue or firewall (try to connect to MongoDB from your machine directly with cli / even running a basic program that uses only mongo driver).
From the stacktrace I don't see any usage of Spring, so more information is required to say for sure.
In general you can analyze the dependencies in Gradle by using gradle dependencies command (see here).
I had the same exception when trying to connect MongoDB with spring-boot.
In my case, I forgot to add the #Configuration annotation in the MongoDB Configuration class I created.
After adding this it worked for me.
I changed the scope(It was Test before)
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>4.2.3</scope>
</dependency>
In my case the mistake was not to have authorized my development environment. So I allowed connections from any IP (not a good idea for prod env) by adding the rule 0.0.0.0/0. You add this rule from the Network Access section from the atlas dashboard.
In my case mongoDB internal port was not mapped to external. Using command docker run -p 27017:27017 -d mongo resolved my issue.
check your mongo with cmd "mongo" if mongo is deathed follow step
1: open search windown
2: search "services"
3: find MongoDB Service and right click then click start on popup
It seems your server is not running.
Also if it running, it is doing so on a different port.