Doncho Balamjiev Doncho Balamjiev - 1 year ago 134
Java Question

JntelliJ can't find driver class

I used IntelliJ IDEA 14.0, Tomcat server and h2 database to create simple Web App.
Unfortunately when I run the application I receive message for exception

java.lang.ClassNotFoundException: org.h2.Driver


I stored h2 jar file in folder with name "db" and set "Add as library" function.
I connect to the DB like this:

public class DBConn {

private static final String DRIVER = "org.h2.Driver";
private static final String URL = "jdbc:h2:tcp://localhost/~/BigPicture";
private static final String USERNAME = "doncho";
private static final String PASS = "";
private static DBConn instance;
private static Connection conn;

private DBConn(){


public static DBConn getInstance(){
if(instance == null){
instance = new DBConn();
return instance;

public Connection getConnectivity(){
try {
} catch (SQLException e) {
return conn;


private void Conn() throws SQLException{
if(conn == null){
try {
} catch (ClassNotFoundException e) {
System.out.println("No Driver Found");
DriverManager.getConnection(URL, USERNAME, PASS);

public void Disconnect(){

if(conn != null){
try {
conn = null;
} catch (SQLException e) {


And I call database in Servlet.

public class DBServlet extends HttpServlet {

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

Connection conn = DBConn.getInstance().getConnectivity();
System.out.println("It Work's");


The Output says "No Driver Found" and throws
java.lang.ClassNotFoundException: org.h2.Driver.

It's importand to say, that when I call class
() in
method IntelliJ fInd
driver, but Tomcat still can't.

Please help because I'm new in IntelliJ and in Eclipse this app work, but I want to use IntelliJ for my projects.

Best regards.

Answer Source

Place driver's jar file on $TOMCAT_HOME/lib or yourapp/WEB-INF/lib

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download