Apache Derby - 返回空结果集的所有查询

时间:2014-05-02 07:32:00

标签: sql derby resultset

目前有以下内容:

package edu.unsw.comp9321.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;     
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import edu.unsw.comp9321.common.ServiceLocatorException;

public class HotelOwnerDAOImpl implements HotelOwnerDAO{


static Logger logger = Logger.getLogger(HotelOwnerDAOImpl.class.getName());
private Connection connection;

public HotelOwnerDAOImpl() throws ServiceLocatorException, SQLException{
    connection = DBConnectionFactory.getConnection();
    logger.info("Got connection");      
}


@Override
public List<HotelOccupancyDTO> getRooms() {

    ArrayList<HotelOccupancyDTO> hotelOccupancyInfo = new ArrayList<HotelOccupancyDTO>();

    try{
        Statement stmnt = connection.createStatement();
        // Retrieve number of hotels in database
        String query_NoHotels = "SELECT MAX(ID) FROM HOTELS";       

        ResultSet res = stmnt.executeQuery(query_NoHotels);
        logger.info("The result set size is "+res.getFetchSize());

        //int noHotels = res.getInt(1);
        //System.out.println("There are " +noHotels + "hotels");    // REMOVE!!



    }catch(Exception e){
        System.out.println("Caught Exception");
        e.printStackTrace();
    }

    return hotelOccupancyInfo;
}

}

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context debug="1" reloadable="true" crossContext="true">
<Resource name="jdbc/cs9321" auth="Container" type="javax.sql.DataSource"
  username="user" password="password" driverClassName="org.apache.derby.jdbc.ClientDriver"     url="jdbc:derby://localhost:1527/hotel" maxActive="8" maxIdle="4" />

但是无论我输入什么SQL查询,我都会得到一个空的结果集。 logger.info行也打印出"Got Connection"

有人会对我应该研究什么有任何建议吗?

谢谢。

0 个答案:

没有答案