kave
kave

Reputation: 1

how to to connect and use JDBCUtil

hi i want to use Class JDBCUtil in java language and eclips workspace and I have the below code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCUtil {

static final String CONN_STR = "jdbc:hsqldb:hsql://localhost/";

static {
    try {
        Class.forName("org.hsqldb.jdbcDriver");
    } catch (ClassNotFoundException ex) {
        System.err.println("Unable to load HSQL JDBC driver");
    }
}

public static Connection getConnection() throws SQLException {
    return DriverManager.getConnection(CONN_STR);
}

}

but when I run it, I get the below Exception:

Unable to load HSQL JDBC driver
Exception in thread "main" java.lang.NullPointerException
    at domain.EnrollCtrl.getCurrentOfferings(EnrollCtrl.java:78)
    at ui.UI.main(UI.java:28)

in addition there is UI and EnrollCtrl and another file in this project but the error is in this path. how can i fix this error? should I do sth for connectin to jdbc:hsqldb:hsql://localhost/? thank U

Upvotes: 0

Views: 938

Answers (2)

Gareth Davis
Gareth Davis

Reputation: 28069

The chances are that you are missing the hsqldb.jar file from your classpath or some other environmental issue.

It is difficult to be certain as your question is incredibly specific to your code and environment.

Upvotes: 0

Ravi Parekh
Ravi Parekh

Reputation: 5622

your String CONN_STR = "jdbc:hsqldb:hsql://localhost/"; should be

conn = DriverManager.getConnection(jdbc:hsqldb:hsql://localhost/xdb", "sa", "");

In some circumstances, you may have to use the following line to get the driver.

Class.forName("org.hsqldb.jdbcDriver").newInstance();

Upvotes: 1

Related Questions