maximus
maximus

Reputation: 11524

ERROR: failed to load JDBC driver - org.hsqldb.jdbcDriver

i wrote a connector class to connect to the hsqldb.

here is my code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.log4j.Logger;


public class hsqlmanager {

        private static final Logger log = Logger.getLogger(hsqlmanager.class);

        private static Connection con=null;

        private static void openConnection(){
            try {
                Class.forName("org.hsqldb.jdbcDriver" );
                log.info("Loaded JDBC Driver");
            } 
            catch (Exception e) {
                log.error("ERROR: failed to load JDBC driver - " + e.getMessage());
                return;
            }

            try {
                con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/sepm_db","sa","");      
            }
            catch(SQLException e){
                log.error(e.getMessage());
            }
        }

        public static void closeConnection() {
            try {
                con.close();
            }
            catch(SQLException e) {
                log.error(e.getMessage());
            }
        }

        public static Connection getConnection() {
            if (con==null){
                openConnection();
            }
            else {
                try {
                if(con.isClosed()){
                    con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/sepm_db","sa","");

                }
                }
                catch(SQLException e){
                    log.error(e.getMessage());
                    return null;
                }
            }

            return con;
        }

}

When I compile that I get ERROR: failed to load JDBC driver - org.hsqldb.jdbcDriver. Why?

Upvotes: 2

Views: 10850

Answers (2)

lord5et
lord5et

Reputation: 500

Try following dependency config in your pom.xml (change your version number accordingly)

<dependency>
   <groupId>org.hsqldb</groupId>
   <artifactId>hsqldb</artifactId>
   <classifier>jdk8</classifier>
   <version>2.6.1</version>        
</dependency>

For me adding that classifier line solved an issue. Please see below recommendation in hsqldb repo. https://sourceforge.net/p/hsqldb/bugs/1644/

Upvotes: 0

basiljames
basiljames

Reputation: 4847

You need to download hsqldb and give it in your classpath. The driver is located in the zip file.

Upvotes: 2

Related Questions