我正在嘗試使用JDBC,並且我的查詢在某些情況下工作,但在其他情況下無法工作。 我真的很感激任何幫助。JDBC的奇怪問題,select返回null
我的一些代碼:
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;
然後結果集retunrs沒什麼.... 我打破我的頭在這裏,仍然無法弄清楚是什麼問題
你嘗試運行它之前打印查詢到控制檯?取出該輸出,然後直接對數據庫運行它。 – BobbyShaftoe 2009-05-24 10:26:54
謝謝,你是對的。 我希望我能給你的評論接受答案。 – Dmitris 2009-05-24 11:04:05