查詢主要代碼塊:
public Object[][] queryBookByName(String type, String bookName) {
// 測試值type = "進貨", bookName = "C++"
Object[][] resultObjects = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
conn = ConnectionSql.connectionSql();
if(type.equals("進貨")) {
String sql = "select * from bookInList where bookName=?";
if(conn!=null) {
try {
statement = conn.prepareStatement(sql);
statement.setString(1, bookName);
resultSet = statement.executeQuery();
int count = 0; //這一步resultSet為空,得不到結果
if(resultSet.next()) {
resultSet.last();
count = resultSet.getRow();
resultObjects = new Object[count][3];
resultSet.beforeFirst();
......
}
} catch (Exception e) {
// TODO: handle exception
} finally {
ConnectionSql.closeConnection(conn, statement, resultSet);
}
}
數據庫是有數據的,但是就是查不出來,jdbc連接等等正常~
如果在數據庫使用"select * from bookInList where bookName='C++' "是可以得到結果的。是不是因為bookName的數據類型是nvchar(20)的原因,求解?
應該不是。感覺是statement.setString(1, bookName);這一塊前後出問題了。