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] +"')");
}
精彩评论