如何从我的servlet类访问放在/ tmp文件夹中的sqlite db文件?

时间:2014-01-09 18:38:51

标签: java sqlite servlets jdbc sqlitejdbc

我正在编写一个JSP-Servlet应用程序,我需要在sqlite db中写入和读取。 db是临时的,我的一个cron作业将数据写入其中,而我的servlet-jsp应用程序读取该数据并偶尔更新它

现在我尝试使用以下代码访问数据库

Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:/tmp/test.db");

我在上面的行中收到以下错误

java.lang.UnsatisfiedLinkError: org.sqlite.NativeDB._open(Ljava/lang/String;I)V
    org.sqlite.NativeDB._open(Native Method)
    org.sqlite.DB.open(DB.java:157)
    org.sqlite.Conn.open(Conn.java:170)
    org.sqlite.Conn.<init>(Conn.java:87)
    org.sqlite.JDBC.createConnection(JDBC.java:113)
    org.sqlite.JDBC.connect(JDBC.java:87)
    java.sql.DriverManager.getConnection(DriverManager.java:571)
    java.sql.DriverManager.getConnection(DriverManager.java:233)
    com.cricket.qa.web.Tickets.doGet(Tickets.java:36)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    amazon.actiontrace.generation.servlet.StorageBindingFilter.doFilter(StorageBindingFilter.java:36)
    com.amazon.spnego.http.InitiateAction.run(HttpAuthFilter.java:215)
    java.security.AccessController.doPrivileged(Native Method)
    javax.security.auth.Subject.doAs(Subject.java:415)
    com.amazon.spnego.http.HttpAuthFilter.executeFilterWithCreds(HttpAuthFilter.java:173)
    com.amazon.spnego.http.HttpAuthFilter.doFilter(HttpAuthFilter.java:74)
    com.amazon.build.brazil.filters.FQDNFilter.doFilter(FQDNFilter.java:170)

1 个答案:

答案 0 :(得分:3)

好的,我用apache derby解决了类似的要求,你可以使用它:

String path = this.getServletContext().getRealPath("tmp/test.db");
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:"+path);