gpt4 book ai didi

exception - PgSQL 异常 : column name not found

转载 作者:行者123 更新时间:2023-11-29 11:37:16 24 4
gpt4 key购买 nike

我在我的应用程序中使用带有 jdk 1.6 的 postgresql-8.3-603.jdbc4.jar 来执行数据库操作。我有时会遇到以下异常,重新启动有助于暂时避免这种异常。

org.postgresql.util.PSQLException:在此结果集中找不到列名 sender_id。 在 org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2502) 在 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) 在 com.netcore.bulkrequest.core.BulkRequestValidate.getBulkRequestTaskObject(BulkRequestValidate.java:104) 在 com.netcore.bulkrequest.core.BulkRequestValidate.run(BulkRequestValidate.java:57) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:619)

这是代码片段:

公共(public)类 FeedDAO { /** * 数据库连接池对象 */ 私有(private)最终 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(); }
}
}

任何人都可以帮我找到永久修复程序吗?

谢谢,摩尼

最佳答案

错误的关键部分是“在此结果集中未找到列名 sender_id”——第一行。那么,如何向我们展示正在寻找不存在的列的查询,以及可能在 pgsql 中交互式执行该查询的结果、模式的相关部分等?当然,您不能指望我们帮助您调试而只看到异常回溯,并且对您的代码和数据库的线索为零!

关于exception - PgSQL 异常 : column name not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1215732/

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