[英]Android SQLite connection/query error
I'm trying to connect SQLite.我正在尝试连接 SQLite。 Connect method:连接方式:
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);
}
And after this:在此之后:
ResultSet rs = db.query(sql);
It give me an error - I'm trying to run the application, and it not working (tell that there some error in app, but not write the error).它给了我一个错误 - 我正在尝试运行该应用程序,但它不起作用(告诉应用程序中存在一些错误,但不写入错误)。 For every SQL command.对于每个 SQL 命令。 I'm using intelliJ, the editor not give errors.我正在使用 intelliJ,编辑器没有给出错误。 Maybe the error with connection, but I not understand the problem.也许是连接错误,但我不明白问题所在。
Android does not know what this "C:\\" is. Android 不知道这个“C:\\”是什么。 You have to use the local filesystem of the android device.您必须使用 android 设备的本地文件系统。 I suggest you read up on this topic here: http://developer.android.com/guide/topics/data/data-storage.html我建议你在这里阅读这个主题: http : //developer.android.com/guide/topics/data/data-storage.html
Instead of giving path in connection try to use而不是在连接中给出路径尝试使用
localhost / localhost IP
For example :例如:
(jdbc:mysql:// { localhost/ localhost IP} / Database_Name)
And for error :对于错误:
import android.util.Log;
Use:使用:
Log.e(Tag,"Error : "+ variable_name(You want to console));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.