How to access my sqlite db file placed in /tmp folder from my servlet class?

2.7k views Asked by At

I am writing a JSP-Servlet application where I need to write to and read from a sqlite db. The db is temporary one to which one of my cron jobs write data to and my servlet-jsp app reads thise data and occasionally updates it

Now I am trying to access the db using following code

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

I get the following error on the above line

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

There are 1 answers

1
Cesar Loachamin On BEST ANSWER

Ok I resolved a similar requirement with the apache derby you could use this:

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