Question

I am using JBOSS AS 7.0.2. I want to create a connection to mysql server the old way (I know I should use JNDI, but I just need it for some quick thing):

Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(.....);

I have mysql-connector-java-5.1.18-bin.jar included under C:\Java\jboss-as-7.0.2.Final\standalone\deployments. I also added it under build path. I can see my tables through Data Source Explorer. But when I try to connect to it through code, it throws exception when it tries to create new instance:

Class.forName("com.mysql.jdbc.Driver").newInstance();

The ClassNotFoundException catch clause catches this exception:

Error: com.mysql.jdbc.Driver from [Module "deployment.Seminarska.war:main" from Service Module Loader]

I have found this thread with this solution:

As a rule you should not be including your JDBC drivers in your war file.

I suggest you mark the driver as provided and add it to the lib directory of the server.

What does mean mark the driver as provided? How does one do that?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top