我正在使用 twitter4j 的流式 API 来收集推文。我在 java 平台上做这个。我在控制台收到推文流,但无法存储。
public void onStatus(Status status) {
try
{
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost/twitterapi";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "twitterapi", "");
String query = " insert into tweets"
+ "(tweet_id,tweet_text,screen_name)" + " values"
+ "('" + status.getId() + "','" +
status.getText() + "', '" +
status.getUser().getScreenName() +"')";
Statement statement = conn.createStatement();
statement.executeUpdate(query);
conn.close();
}
catch (Exception e)
{
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
System.out.println("onStatus @" + status.getUser().getScreenName() + " - " + status.getText());
}
请考虑所有其他事情都是正确的,因为它已经在工作了。
最佳答案
在您的insert
中,您的列数与值不同。您没有指定 author_id。
此外,正如 DaveH 所注意到的,您实际上并没有针对服务器运行 SQL 命令。
关于java - 使用java从流式api将推文存储在mysql中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42489961/