【发布时间】:2010-10-28 13:23:17
【问题描述】:
我正在尝试使用 JDBC,但我的查询在某些情况下有效,但在其他情况下无效。 非常感谢任何帮助。
我的一些代码:
public Result getSpecificTopic()
{
String query = "Select msg_body, msg_author from lawers_topic_msg";// where msg_id=2 order by msg_id desc";
try
{
con = mysql.getConnection();
//Statement stmt = con.createStatement();
PreparedStatement stmt = con.prepareStatement(query);
//stmt.setInt(1, topicId);
ResultSet rs = stmt.executeQuery(query);
int rowCount = rs.getRow();
specificTopic = ResultSupport.toResult(rs);
con.close();
stmt.close();
}
catch(Exception e)
{
}
return this.specificTopic;
}
public void setTopicId(String num)
{
this.topicId = Integer.parseInt(num);
}
public int getTopicId()
{
return this.topicId;
}
如果我改变了
String query = "Select msg_body, msg_author from lawers_topic_msg";
到
String query = "Select msg_body, msg_author from lawers_topic_msg where msg_id = " + topicId;
然后结果集没有返回任何内容.... 我在这里打破了我的头,仍然无法弄清楚问题是什么
【问题讨论】:
-
您是否尝试在运行前将查询打印到控制台?获取它的输出,然后直接针对您的数据库运行它。
-
谢谢,你是对的。我希望我能给你评论接受的答案。