hi
i want to use Class JDBCUtil
in java language and eclips workspace and I have the below code:
import java.sql.Connection;
im开发者_运维百科port 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
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();
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.
精彩评论