[英]ERROR [stderr] (EJB default - 8) java.lang.ClassNotFoundException: org.sqlite.JDBC
I'm trying to make a connection with sqlite database in j2ee project, but i keep getting this error "ERROR [stderr] (EJB default -8)java.lang.ClassNotFoundException: org.sqlite.JDBC". 我正在尝试与j2ee项目中的sqlite数据库建立连接,但我不断收到此错误“ ERROR [stderr](EJB默认为-8)java.lang.ClassNotFoundException:org.sqlite.JDBC”。 Knowing that I test the method in java program and that's work fine.
知道我在Java程序中测试了方法,就可以了。 I have one connection class in ejb project(session bean)there is the code here.
我在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;
}
then I test it with junit test in java project but everytime i get the same error :java.Lang.ClassNotFoundException: org.sqlite.JDBC PS: I have incuded sqlite.jar like this (right click on the project->configure build path-> library-> add external jar) but always facing the same error 然后我在Java项目中用junit test对其进行测试,但是每次遇到相同的错误时:java.Lang.ClassNotFoundException:org.sqlite.JDBC PS:我像这样引入了sqlite.jar(右键单击project-> configure build path ->库->添加外部jar),但始终面临相同的错误
I have fixed the problem: 我已经解决了这个问题:
Added SQLite jar file in this path: 在此路径中添加了SQLite jar文件:
D:\\jboss-as-7.1.1.Final\\modules\\javax\\activation\\api\\main D:\\ jboss-as-7.1.1.Final \\ modules \\ javax \\ activation \\ api \\ main
In JBoss Server Runtime > Deployments > Manage Deployments added SQLite jar file an then enable it. 在JBoss Server运行时 > 部署 > 管理部署中添加了SQLite jar文件,然后将其启用。
Assuming that you have the following project structure: 假设您具有以下项目结构:
src/main/java
|
- MyConnection.java
src/test/java
|
- MyConnectionTest.java
With the following elements: 具有以下元素:
Base class MyConnection
基类
MyConnection
public class MyConnection {
public Connection getConnection() {
Connection connection = null;
try {
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:");
System.out.println("Connection completed.");
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
}
Test class MyConnectionTest
测试类
MyConnectionTest
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.sql.Connection;
import java.sql.SQLException;
import org.junit.Test;
public class MyConnectionTest {
@Test
public void isValid() throws SQLException {
MyConnection myConn = new MyConnection();
Connection conn = myConn.getConnection();
assertTrue(conn.isValid(0));
conn.close();
assertFalse(conn.isValid(0));
}
}
In your Eclipse project you just need to do the following: 在Eclipse项目中,您只需执行以下操作:
MyConnectionTest
test class and run it as a JUnit test. MyConnectionTest
测试类,然后将其作为JUnit测试运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.