我正在从网站上抓取应用程序的数据,我正在尝试将这些数据存储在SQLite数据库中 - JSoup + Android

时间:2016-04-18 14:54:32

标签: android database sqlite android-studio

我正在使用android studio和jsoup从网站上抓取数据并在手机上显示。我希望将抓取的数据存储在android中的SQLite数据库中。然而,当我按照教程(如http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/)时,我总是陷入困境。这是教程正在失去我。我尝试添加文本,但我无法克服错误。

    db.addContact(new Contact("Ravi", "9100000000"));        
    db.addContact(new Contact("Srinivas", "9199999999"));
    db.addContact(new Contact("Tommy", "9522222222")); 

varible String文本是我想要存储在数据库中的数据。有没有人知道如何在SQLite数据库中存储这种类型的数据?

 String text = doc.select("#post-15 > div > table:nth-child(6) > tbody > tr:nth-child(2) > td:nth-child(2) > table:not(:last-of-type)").text();

这会添加到我正在抓取数据的方法中。

                DatabaseHandler db = new DatabaseHandler(this);
                Log.d("Insert: ", "Inserting ..");
                db.addContact(new Contact(1, "9"+text));


                // Reading all contacts
                Log.d("Reading: ", "Reading all contacts..");
                List<Contact> contacts = db.getAllContacts();

                for (Contact cn : contacts) {
                    String log = "Id: "+cn.getID()+" ,Name: " + cn.get_text() ;
                    // Writing Contacts to log
                    Log.d("Name: ", log);
                }

0 个答案:

没有答案