SolKool
SolKool

Reputation: 13

Problems connecting to h2 database in wildfly

I already created the database in wildfly and it's all correct since I can access it from within eclipse. I created a DataSource in wildfly as java:jboss/datasources/Test5JPA and testing it gives no problems. Now I want to test if I can access it from a different java project (in eclipse) and there's where my problem starts.

I was told to try something like this to connect to the DB but I can't make it work:

Connection connection = null;
Statement statement = null;
boolean resultOfInsert = false;

Class.forName("org.h2.Driver");
connection = DriverManager.getConnection("java:jboss/datasources/Test5JPA");
statement = connection.createStatement();
resultOfInsert = statement.execute("INSERT INTO person (id1, name) VALUES('12','test');");

And I get this error:

13:32:20,642 ERROR [stderr] (default task-15) java.lang.ClassNotFoundException: org.h2.Driver from [Module "deployment.Tarea3.war:main" from Service Module Loader]

13:32:20,642 ERROR [stderr] (default task-15)   at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)

13:32:20,642 ERROR [stderr] (default task-15)   at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443)

13:32:20,642 ERROR [stderr] (default task-15)   at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431)

13:32:20,642 ERROR [stderr] (default task-15)   at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373)

13:32:20,642 ERROR [stderr] (default task-15)   at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118)

13:32:20,642 ERROR [stderr] (default task-15)   at java.lang.Class.forName0(Native Method)

13:32:20,642 ERROR [stderr] (default task-15)   at java.lang.Class.forName(Unknown Source)

I was told to download org.h2.Driver and I got it from here: http://www.java2s.com/Code/Jar/h/Downloadh2jar.htm but it didn't help.

Also changing the connection to : connection = DriverManager.getConnection("jdbc:h2:file:~/final-jpa/Test5JPA"); doesn't help either.

Upvotes: 1

Views: 1874

Answers (1)

mendieta
mendieta

Reputation: 3500

You are getting a ClassNotFoundException, looks like you did not copy your h2 jar correctly.. Make sure you place it in your lib folder of your war..

Upvotes: 1

Related Questions