gpt4 book ai didi

java - PreparedStatement 上的 ArrayOutOfBoundsException

转载 作者:行者123 更新时间:2023-11-30 08:55:43 25 4
gpt4 key购买 nike

我在这里不知所措,任何人都可以看出这段代码有什么问题吗?我在这个驱动程序中使用 sqlite: https://bitbucket.org/xerial/sqlite-jdbc/downloads

编辑:修复了我最初的错误,但有一个类似的错误

public void insertTweets(final List<WatchedTweet> tweets) {
try {
final PreparedStatement stmt = connection.prepareStatement(
"insert into tweets(tweet_id, user_id, campaign_id, retweet_count, date) values(?,?,?,?,?)"
);
for(WatchedTweet tweet : tweets) {
stmt.setLong(1, tweet.getID());
stmt.setLong(2, tweet.getParent().getTwitterID());
stmt.setInt(3, tweet.getParent().getCampaignID());
stmt.setInt(4, tweet.getRetweetCount());
stmt.setLong(5, tweet.getAdded().getTime());
stmt.addBatch();
stmt.clearParameters();
}
stmt.executeBatch();
stmt.close();
} catch (SQLException sqe) {
sqe.printStackTrace();
}
}

我在这一行遇到异常:

stmt.setLong(1, tweet.getID());

异常:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at org.sqlite.core.CorePreparedStatement.batch(CorePreparedStatement.java:110)
at org.sqlite.jdbc3.JDBC3PreparedStatement.setLong(JDBC3PreparedStatement.java:298)
at tweetserver.server.db.TwitterDB.insertTweets(TwitterDB.java:75)
at tweetserver.server.rest.TwitterBot.updateTimelineUntilDate(TwitterBot.java:138)
at tweetserver.server.rest.TwitterBot.process(TwitterBot.java:49)
at tweetserver.server.rest.TwitterBot.<init>(TwitterBot.java:44)
at tweetserver.server.Application.bootstrap(Application.java:25)
at tweetserver.server.Application.main(Application.java:20)

这是我创建表格的方式

"create table if not exists tweets (" +
"id integer PRIMARY KEY AUTOINCREMENT," +
"tweet_id long NOT NULL," +
"user_id long NOT NULL," +
"campaign_id int NOT NULL, " +
"retweet_count int NOT NULL, " +
"date long NOT NULL)"`

最佳答案

根据 http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html#setLong(int,%20long) 上的文档

parameterIndex - the first parameter is 1, the second is 2, 

关于java - PreparedStatement 上的 ArrayOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com