Question

Can anyone think of a reason why this piece of code, looped (exactly 12 times) never returns any data, while the same statement entered in SQL Server SMS, gives me exactly what I'm looking for? When debugging, the rset.next() returns false and never enters the loop.

Connection connection = null;
PreparedStatement statement = null;
ResultSet rset = null;
ArrayList<PriceList> priceLists = new ArrayList<PriceList>();
String sqlStatement = "";
int i = 1;
try {
    connection = pool.getConnection();
    sqlStatement = "SELECT DISTINCT PriceList.ExRateAbbr FROM PriceList WHERE PLName Like ?;";
    statement = connection.prepareStatement(sqlStatement);
    statement.setString(i++, pricelistName);
    rset = statement.executeQuery();
    while (rset.next()) {
            PriceList pList = new PriceList();
            pList.setCurrency(rset.getString("ExRateAbbr"));
            priceLists.add(pList);
    }
    statement.close();
} catch (SQLException sqle) {
    sqle.printStackTrace();
} finally {
if (pool != null) {
    try {
        pool.releaseConnection(connection);
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    }
}

This worked when I was using Access as a database, but after moving whole db to SQL Server there's nothing. And no exceptions thrown. I'm at a loss and all I can think of is that there is some SQL Server limitations for opening and closing connections very quickly.

Was it helpful?

Solution

Changing my query to:

SELECT DISTINCT PriceList.ExRateAbbr FROM PriceList WHERE PLName=?;

solved it. But why would the query using LIKE not work ? Strange enough it worked when it was executed in SQL Server SMS, so what's the deal here?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top