Tuesday, February 14, 2012

Re: Incorrect SELECT results in GAE/SQL cloud JDBC?

Here is the BD schema.

create table forecasts
(
forecast_id int unique not null auto_increment,
forecast_date DATE,
require_by DATE,
storage_type int,
capacity_gb int,
forecaster varchar(25),
application varchar(255),
servers varchar(255),
active boolean
);

And here are the functions from the MVC Controller. First the
getForecasts() that is the query that isn't working as expected. The
executeQuery() returns only an empty ResultSet with no records
fetched.

private ResultSet getForecasts()
{
//ResultSet set;
//String haveForecasts=(String)
currentSession.getAttribute("haveForecasts");
//if ( haveForecasts ==null || haveForecasts.equals("n"))
//{
//String getForecasts="select * from forecasts where
active=true";
String getForecasts="SELECT forecast_id, forecast_date,
require_by, storage_type, capacity_gb, forecaster, application,
servers, active FROM forecasts";

logger.info(getForecasts);
try
{
//set=stmt.executeQuery(getForecasts);
return(stmt.executeQuery(getForecasts));
//logger.info("Fetched Size: "+set.getFetchSize());
}
catch(Exception e)
{
e.printStackTrace();
logger.severe("On getting the Forecasts from Database\n"+e);
}
//}
return (ResultSet) null;
}


There is alot of stuff commented out that looks redundant, but this
was only for troubleshooting

This delete function works correctly.
private void deleteForecast(String passedID)
{
String delete_stmt="update forecasts set active=false where
forecast_id='"+passedID+"';";
logger.info(delete_stmt);
try
{
stmt.executeUpdate(delete_stmt);
}
catch(Exception e) {e.printStackTrace(); }
}

And here us how I initialized the DB.

else if ( google.equals("true"))
{
DriverManager.registerDriver(new AppEngineDriver());
logger.info("DB Parms: "+driver+" : "+url);

//Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url);
}
else
{
logger.info("Unknown Database to open");
}
stmt=conn.createStatement();
logger.info("Database connection established");
}

Hope this help, there is alot of other code, but this is really all
that is involved in the query.

Any insight would be appreciated.

Randall

No comments:

Post a Comment