public ResultSet updateSql(String sql) throws SQLException {
Statement sta = conn.createStatement();
return sta.executeUpdate(sql);
}
這是機能的研究在聽衆conn將類型不匹配:不能從int轉換爲結果
但聽者錯誤
return sta.executeUpdate(sql);
類型不匹配:不能從int轉換爲結果
public ResultSet updateSql(String sql) throws SQLException {
Statement sta = conn.createStatement();
return sta.executeUpdate(sql);
}
這是機能的研究在聽衆conn將類型不匹配:不能從int轉換爲結果
但聽者錯誤
return sta.executeUpdate(sql);
類型不匹配:不能從int轉換爲結果
return sta.executeUpdate(sql);
這會返回查詢執行後受影響的行數,例如(INSERT/UPDATE/DELETE),即executeUpdate()的返回類型是整數。這不會返回任何結果集。當使用諸如SELECT查詢之類的查詢時,即當你必須從表格中拉出行時,使用ResultSet。從表中拉出後,它放置在ResultSet中以便在java中進一步處理。
這就是爲什麼錯誤顯示:
Type Missmatch : cannot convert from Int to ResultSet
感謝您的答案btw,這是幾分鐘前的工作。 –
很高興幫助。如果有幫助,也不要忘記檢查答案。謝謝 :) – anishroniyar
public int updateSql(String sql) throws SQLException {
Statement preparedStatement = conn.prepareStatement(toString(), Statement.RETURN_GENERATED_KEYS);
return preparedStatement.executeUpdate(sql);
}
你檢查什麼 「的executeUpdate」 回報? – Stultuske
http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html – Stultuske
您的文章標題真的很難閱讀,並會甩開潛在的回覆。請修正拼寫/語言錯誤,並將其作爲一個清晰,簡潔的標題,它會幫助您獲得答案。 – Buurman