【问题标题】:Android SQLite connection/query errorAndroid SQLite 连接/查询错误
【发布时间】:2013-11-16 19:34:59
【问题描述】:

我正在尝试连接 SQLite。 连接方式:

public void connect() throws SQLException, ClassNotFoundException
{
    Class.forName("org.sqlite.JDBC");
    Connection conn = DriverManager.getConnection("jdbc:sqlite:C:\\..MY_PATH..\\data\\db.sqlite");
    stmt = conn.createStatement();
}


public ResultSet query(String sql) throws SQLException
{
    return stmt.executeQuery(sql);
}

然后:

ResultSet rs = db.query(sql);

它给了我一个错误 - 我正在尝试运行应用程序,但它不工作(告诉应用程序中有一些错误,但不要写错误)。对于每个 SQL 命令。我正在使用intelliJ,编辑器不会出错。 可能是连接错误,但我不明白问题所在。

【问题讨论】:

    标签: java android sqlite intellij-idea


    【解决方案1】:

    Android 不知道这个“C:\”是什么。您必须使用 android 设备的本地文件系统。我建议你在这里阅读这个主题:http://developer.android.com/guide/topics/data/data-storage.html

    【讨论】:

      【解决方案2】:

      不要给出连接路径,而是尝试使用

      localhost / localhost IP
      

      例如:

      (jdbc:mysql:// { localhost/ localhost IP} / Database_Name)
      

      对于错误:

      import android.util.Log;
      

      用途:

      Log.e(Tag,"Error : "+ variable_name(You want to console));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多