Reputation: 13
I'm using Wildfly 10 and my datasource in the standalone.xml is:
<datasources>
<datasource jta="true" jndi-name="java:/MySqlDS" pool-name="MySQL_AAA" enabled="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/aaa</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql-connector-java-5.1.35-bin.jar_com.mysql.jdbc.Driver_5_1</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
I'm running this code in my Java bean:
Class.forName("com.mysql.jdbc.Driver");
and I get this error message:
10:29:59,210 ERROR [stderr] (default task-15) java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "deployment.AAA_5.war:main" from Service Module Loader]
10:29:59,210 ERROR [stderr] (default task-15) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
I read documentation that said I needed to have the driver in my lib folder but that didn't work. I'm sure the solution is simple but I don't see it. Can someone point me in the right direction. Some documentation that I can use as a resource would be great.
Upvotes: 1
Views: 2006
Reputation: 765
Drop mysql driver in the deployments
folder in your wildfly , it will be deployed automatically , then it will become available.
EDIT:
installing mysql JDBC driver in wildfly as deployment will not give you access to mysql classes because of class-loaders behaviors, you can access the database connections through jndi
datasources only, and you will not need to use Class.forName()
.
InitialContext context=new InitialContext();
DataSource d=(DataSource)context.lookup(yourDataSourceName);
However, if you still need to use mysql specific classes in your project , you have to drop the driver in your web-project/WEB-INF/lib
folder.(but be careful about this since it will not be related to the deployed driver)
Upvotes: 1