【发布时间】:2016-03-08 09:46:33
【问题描述】:
我正在尝试与 j2ee 项目中的 sqlite 数据库建立连接,但我不断收到此错误“错误 [stderr] (EJB 默认 -8)java.lang.ClassNotFoundException: org.sqlite.JDBC”。知道我在 java 程序中测试了该方法并且工作正常。 我在 ejb 项目(会话 bean)中有一个连接类,这里有代码。
public Connection getConnection(){
Connection connection= null;
try {
Class.forName("org.sqlite.JDBC");
String dataFolder = System.getProperty("user.home") + "\\AppData\\Local";
String b = System.getProperty("user.home") ;
String file = b + "\\Desktop\\file";
connection = DriverManager.getConnection("jdbc:sqlite:"+ file );
System.out.println("Connection completed.");
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
然后我在 java 项目中使用 junit 测试对其进行测试,但每次我得到相同的错误:java.Lang.ClassNotFoundException: org.sqlite.JDBC PS:我有这样的sqlite.jar(右键单击项目->配置构建路径->库->添加外部jar)但总是面临同样的错误
【问题讨论】:
-
java.Lang.ClassNotFoundException真的发生在什么时候?!无论是在您的应用程序运行时还是在您运行 JUnit 测试时? -
当我运行 junit 测试时@aribeiro
-
您是否使用 Maven 来构建和打包您的应用程序?
-
我使用 jboss 7.1 作为服务器,使用 eclipse 作为 IDE @aribeiro
标签: java sqlite jakarta-ee ejb database-connection