0

我的项目有问题,这是我的 pTwitterEx.java

import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @author tasgnab
 * how to use:
 * 1. copy-paste folder tempat menyimpan hasil crawl per topik pada variabel dir
 * 2. masukkan topik sabagai label di databae pada variabel topik
 * 3. run file
 */
public class pTwitterEx {
    private static Database db = new Database();
    private static String dir = "D:\\KULIAH\\semester7\\TA2\\java\\dataset\\baik";
    private static String topik = "baik";
    private static int count=0;
    public static void main(String[]args){
        db.query("truncate twitter");
        String temp="a";
        while (!"iniadalahpenanda".equals(temp)){
            FileRead fr = new FileRead(dir+count);
            try {
                JSONObject J = new JSONObject(fr.getTeks());
                String C = J.get("text");
                db.query("insert into twitter values '"+C+"','"+topik+"'");
            } catch (JSONException ex) {
                temp = "iniadalahpenanda";
                //System.exit(0);
                //Logger.getLogger(pTwitterEx.class.getName()).log(Level.SEVERE, null, ex);
            }
            count++;
        }
        //db.query("insert into twitterfix select distinct comment,'"+topik+"' from twitter");
    }
}

我的问题是,从文件夹“baik”到我的mysql数据库的数据。我的数据库中的字段名称是 text(type : text) 和 topik(type : varchar)。

当我运行程序时,它没有显示错误,但我的数据库中的数据仍然是空的。你能帮我解决我的问题吗?任何帮助将不胜感激......无论如何谢谢......

4

2 回答 2

0

要完成数据库中的表达式(至少在 MySQL 中),请添加“;” 在一行的末尾。

对不起,改变这一行:

db.query("insert into twitter values '"+C+"','"+topik+"'");

到这一行:

db.query("insert into twitter values '"+C+"','"+topik+"';");
于 2012-12-06T16:13:52.837 回答
0

你的查询应该是这样的:观察大括号()

例子:

db.query("insert into twitter values( '"+C+"','"+topik+"')");
于 2012-12-06T16:28:45.367 回答