我在我的应用程序中使用postgresql-8.3-603.jdbc4.jar和jdk 1.6进行数据库操作。我有时会得到以下异常,并且重启有助于暂时避免这种异常。
org.postgresql.util.PSQLException:在此ResultSet中找不到列名sender_id。 at org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2502) at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:2345) 在org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:225) 在org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:225) 在com.netcore.bulkrequest.db.FeedDAO.setFeedDetails(FeedDAO.java:142) 在com.netcore.bulkrequest.feed.Feed.getInstance(Feed.java:37) 在com.netcore.bulkrequest.core.BulkRequestTask。(BulkRequestTask.java:86) at com.netcore.bulkrequest.core.BulkRequestValidate.getBulkRequestTaskObject(BulkRequestValidate.java:104) 在com.netcore.bulkrequest.core.BulkRequestValidate.run(BulkRequestValidate.java:57) at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908) 在java.lang.Thread.run(Thread.java:619)
以下是代码段:
公共类FeedDAO { / ** *数据库连接池对象 * / private final DBContext dbc;
private final Feed feed;
public static final String SENDER_ID_ATTRIBUTE = "sender_id";
/**
* Constructor
*
* @param dbc
* @param feed
*/
public FeedDAO(DBContext dbc, Feed feed) {
this.dbc = dbc;
this.feed = feed;
}
public void setFeedDetails()抛出SQLException {
String feedDetailsQuery = "SELECT a.priority, b.keyword, b.welcome " +
" FROM feed AS a, pub_feed_info AS b " +
" WHERE a.resource_id = b.resource_id AND b.resource_id = ?";
String senderIdQuery = "SELECT b.attribute_value AS " +
SENDER_ID_ATTRIBUTE + " FROM " +
"attribute_master AS a, feed_attributes AS b " +
"WHERE a.attribute_id = b.attribute " +
" AND a.attribute_name='" + SENDER_ID_ATTRIBUTE + "' " +
" AND feed_id = ?";
Connection con = null;
PreparedStatement fdStmt = null;
PreparedStatement siStmt = null;
try {
con = dbc.getConnection();
//Get the feed details
fdStmt = dbc.getPreparedStatement(con, feedDetailsQuery);
fdStmt.setInt(1, this.feed.getFeedId());
fdStmt.execute();
ResultSet fdResults = fdStmt.getResultSet();
while (fdResults.next()) {
String keyword = fdResults.getString("keyword");
String welcomeMsg = fdResults.getString("welcome");
int priority = fdResults.getInt("priority");
if(null != keyword) {
this.feed.setKeyword(keyword);
} else {
this.feed.setKeyword(String.valueOf(this.feed.getFeedId()));
}
this.feed.setWelcomeMsg(welcomeMsg);
this.feed.setPriority(priority);
}
//Get the sender id
siStmt = dbc.getPreparedStatement(con, senderIdQuery);
siStmt.setInt(1, this.feed.getFeedId());
if(siStmt.execute()) {
ResultSet siResults = siStmt.getResultSet();
while(siResults.next()) {
String senderId = siResults.getString(SENDER_ID_ATTRIBUTE);
this.feed.setSenderId(senderId);
}
} else {
this.feed.setSenderId(Feed.DEFAULT_SENDER_ID);
}
} catch (SQLException ex) {
throw ex;
} finally {
if (fdStmt != null) { fdStmt.close(); }
if (siStmt != null) { siStmt.close(); }
if (con != null) { con.close(); }
}
}
}
任何人都可以帮我找到永久性修复方法吗?
谢谢, 摩尼
答案 0 :(得分:1)
错误的关键部分是“在此ResultSet中找不到列名sender_id” - 第一行。那么,如何向我们展示正在寻找一个不存在的列的查询,以及在pgsql中交互式执行该查询的结果,模式的相关部分等等?当然,你不能指望我们在没有看到异常回溯的情况下帮助你进行调试,没有关于你的代码和数据库的线索!