I am trying to access sqlite.db file in 开发者_如何学Gomy java web app. i can access it with absolute path, but now i want to access it with my webapps relative path. My context.xml looks like
<Context antiJARLocking="true" path="/webappServer">
<Resource name="jdbc/myDB" auth="Container"
type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="1000"
driverClassName="org.sqlite.JDBC"
url="jdbc:sqlite:/db/sqlite.db" />
</Context>
and i call for the connection in my java class
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/myDB");
Connection conn = ds.getConnection();
my sqlite location is in C:\db\sqlite.db but now i want to move it so i can call my sqlite connection with something like localhost/mysqlite.db is it possible ? what should i do to achieve it ?
Thanks !
P.S. Im new to java web app. so any help will be very useful
There are 2 different ways of doing so:
- Define the datasource outside your webapps
Context.xml
inside Tomcat's ownContext.xml
and modify it according to the needs of the different servers. One-time configuration on each server required. - Solve the problem during your build process. Create different
Context.xml
files for all the environments you need, e.g.Context_prod.xml
. During the build process identify the file you need and place it in your webapp.
Those are the 2 approaches I am aware of.
精彩评论