I'm trying to create a query within a results set loop but I keep getting the error "Before start of result set". I've attempted many different methods but they keep coming up with the same error.
Can someone help me out here?
String insertSQL = "INSERT INTO MonthlyReportTable VALUES(NULL,"; //Primary Key.
String PlannetSchemeCode = "";
int ResponcibleAuthorityID = 0;
Statement stmt = ConnectionDetails.getNewConnectionPPARSDB().createStatement();
ResultSet resultsSet = stmt.executeQuery("SELECT * FROM planning_scheme");
Statement insideStatement = ConnectionDetails.getNewConnectionPPARSDB().createStatement();
//Loop though each planning scheme and create the data for each field.
while (resultsSet.next())
{
PlannetSchemeCode = "'" + resultsSet.getString("ps_code") + "'";
//Planning Scheme Primary Key
insertSQL += PlannetSchemeCode + ",";
/*
//Responsible Authority ID
insertSQL += "'" + String.valueOf(
ResponcibleAuthorityID = MySQLUtil.getResults(
ConnectionDetails.Database_Connection_PPARSDB,
"SELECT resp_authority_id " +
"FROM resp_authority_to_ps " +
"WHERE ps_code = " + PlannetSchemeCode
)
.getInt("resp_authority_id")
) + "'";
*/
ResultSet insideResultsSet =
insideStatement.executeQuery(
"SELECT resp_authority_id " +
"FROM resp_authority_to_ps " +
"WHERE ps_code = " + PlannetSchemeCode
);
//ERROR HERE, some reason results set is getting set wrong??
//Error here, this current results set is resetting the Results set.
ResponcibleAuthorityID = insideResultsSet.getInt("resp_authority_id");
//Total_Received_CM
//Add the rest of the values temporary.
int FeildsAdded = 3;
for(int i = 1 + FeildsAdded; i < 458; i++)
{
insertSQL += String.valueOf(0) + ",";
}
//Insert date and end SQL string.
insertSQL += "NOW()";
insertSQL += ")";
System.out.println(insertSQL);
//Do Insert in PPARS.
//stmt.executeQuery(insertSQL);
//Reset the SQL String for the new Row.
insertSQL = "INSERT INTO MonthlyReportTable VALUES(NULL,";
}