尝试连接SQLite数据库的奇怪行为

时间:2014-07-24 23:45:33

标签: java sqlite

我有时间尝试连接到这样的数据库:

public static Connection connect(String url) {
    try {
        Class.forName("org.sqlite.JDBC");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    Connection conn = null;

    try {
        conn = DriverManager.getConnection(url); // (1)
        //conn = DriverManager.getConnection("jdbc:sqlite:settings.db"); // (2)
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return conn;
}

然后我从主叫它......

connect("jbdc:sqlite:settings.db");

仅当我将url放在literal(2)中时才有效,但是当我把它作为变量放置时(1)

其他信息:

有什么想法?我卡住了,谢谢。

编辑:

stacktrace

java.sql.SQLException: invalid database address: jbdc:sqlite:settings.db
    at org.sqlite.JDBC.createConnection(JDBC.java:74)
    at org.sqlite.JDBC.connect(JDBC.java:64)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at lyoneel.Sandbox.connect(Sandbox.java:59)
    at lyoneel.Sandbox.main(Sandbox.java:23)

1 个答案:

答案 0 :(得分:0)

您的代码中有拼写错误:

connect("jbdc:sqlite:settings.db");
         ^^^^ - should be j d b c not j b d c