开发者

how to insert word by word in database

I'm having problems inserting data into a database after a tokenization process. I want to insert one by one word into database. I am using tokenization process to split the sentences. Below is my coding for tokenization process and inserting data:

      //tokenization process
      String speech = Report_tf.getText();
      System.out.println(speech);

   开发者_高级运维   StringTokenizer st = new StringTokenizer(speech);
      while (st.hasMoreTokens()) 
          System.out.println(st.nextToken());

      //insert in database
      String token = st.nextToken(speech);    
      statement.executeUpdate("INSERT INTO laporan (text_laporan) VALUES ('"+ token +"')");
      }


You are missing an opening brace on your while loop. That could be the problem. I'd be surprised if this even compiles.


Start with something like this:

String speech = Report_tf.getText();
String [] tokens = speech.split("\\s");

for (int x=0; x < tokens.length; x++) {
  System.out.println(tokens[x]);
  statement.executeUpdate("INSERT INTO laporan (text_laporan) VALUES ('"+ tokens[x] +"')");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜