SQLite中的初学者 [英] Beginner in SQLite

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

问题描述

我以前没有使用过SQLite,我在寻找是否可以使用它。

I haven't used SQLite before and I am looking if I could use it.

我很困惑。例如,似乎没有一个与SQLite相关联的jdbc驱动程序来自官方的SQLite。

我发现一些帖子/网站(一些出现旧链接)提供的jdbc驱动程序,但我不情愿这些驱动程序如何稳定或如果它们缺少功能。

I am puzzled a bit. For example there does not seem to be a jdbc driver associated with SQLite that comes from the official SQLite.
I have found some posts/sites (some appear old links) that offer the jdbc driver but I am reluctant on how stable these drivers are or if they are missing features.

此外,我不清楚SQLite的用法。

Additionally I am not clear on the usage of SQLite.

例如,我试过下面的代码:

For example I tried the following code:

public static void main(String[] args) throws Exception {
        Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
        Statement stat = conn.createStatement();
        stat.executeUpdate("drop table if exists people;");
        stat.executeUpdate("create table people (name, occupation);");
        PreparedStatement prep = conn.prepareStatement(
            "insert into people values (?, ?);");

        prep.setString(1, "Gandhi");
        prep.setString(2, "politics");
        prep.addBatch();
        prep.setString(1, "Turing");
        prep.setString(2, "computers");
        prep.addBatch();
        prep.setString(1, "Wittgenstein");
        prep.setString(2, "smartypants");
        prep.addBatch();

        conn.setAutoCommit(false);
        prep.executeBatch();
        conn.setAutoCommit(true);

        ResultSet rs = stat.executeQuery("select * from people;");
        while (rs.next()) {
            System.out.println("name = " + rs.getString("name"));
            System.out.println("job = " + rs.getString("occupation"));
        }
        rs.close();
        conn.close();

    }

此代码在我的应用程序目录中创建一个数据库文件。 br>
所以我想jdbc.jar创建这个?

所以我不需要运行我下载的sqlite3.exe?我应该从哪里获得jdbc驱动程序?

This code creates a database file in my application directory.
So I guess the jdbc.jar creates this???
So I don't need to run the sqlite3.exe that I downloaded? Where should I get the jdbc driver from?

更新:

这是我的观点。在PKeidel(http://www.zentus.com/sqlitejdbc/)的答案之一提供的链接是指从2009年起

推荐答案

您可以从这里下载JDBC驱动程序: http://www.zentus.com/sqlitejdbc/

You can download the JDBC Driver from here: http://www.zentus.com/sqlitejdbc/

只有在Windows上使用命令行时才需要sqlite3.exe pc。

The sqlite3.exe is only needed when you work with your command line on your windows pc. You don't need it when you want to access a database with Java.

从Java你必须:
- 下载JDBC驱动程序
- 将它添加到你的项目/ classpath
- 调用 Class.forName(org.sqlite.JDBC);
- 现在你可以使用它例如您的第一篇文章

From Java you have to: - download the JDBC Driver - add it to your project/classpath - call Class.forName("org.sqlite.JDBC"); - now you can use it like in your first post

这篇关于SQLite中的初学者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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