如何在Tomcat 6中配置SQLite? [英] How to configure SQLite in Tomcat 6?

查看:752
本文介绍了如何在Tomcat 6中配置SQLite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请介绍一下如何在tomcat 6中使用sqlite?我正在使用Xerial sqlite jdbc驱动程序。在我的应用程序中,我有多个sqlite数据库(.db文件),并且需要连接到不同的sqlite数据库,具体取决于用户登录的内容?我在哪里可以将所有的.db文件 - 放在webapp根目录中或系统中的任何位置或WEB-INF中?

Can you please provide the steps on how to use sqlite in tomcat 6? I am using Xerial sqlite jdbc driver. In my application, I have got multiple sqlite databases (.db files) and would need to connect to a different sqlite database depending on what user logs in ? Where can I put all the .db files - with in the webapp root's directory or any where on the system or with in WEB-INF?

谢谢,

推荐答案

我们所做的非常相似。遗憾的是,您无法在Tomcat上创建SQLite连接池,因为SQLite为每个用户都有一个数据库文件。

What we did is pretty similar. Unfortunately you cannot create a SQLite Connection pool on Tomcat as SQLite has a database file for each user.

只需复制中的jar文件TOMCAT_HOME / lib 文件夹但您无法通过JNDI调用连接。
你必须这样做:

Just copy the jar file in TOMCAT_HOME/lib folder but you cannot call a connection via JNDI. You will have to do something like this:

/**
     * 
     * @param driverClassName
     * @param url
     * @param user
     * @param password
     * @throws SQLException 
     * @throws Exception 
     */
    public DefaultJdbcTransaction(String driverClassName, String url, String user, String password) throws SQLException {
        super();
        // TODO Auto-generated constructor stub
        try {
            Class.forName(driverClassName).newInstance();

            if (user == null && password == null) {
                connection = DriverManager.getConnection(url);
            } else {
                connection = DriverManager.getConnection(url, user, password);
            }
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            throw new SQLException(e);
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            throw new SQLException(e);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            throw new SQLException(e);
        }
    }

其中 url =jdbc :sqlite:/path/to/sqlite/file/userId.db driverClassName =org.sqlite.JDBC,和( user = password = null )。

我正在使用 sqlitejdbc-v056.jar

希望这会有所帮助

这篇关于如何在Tomcat 6中配置SQLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆