> In you're code the variable values is defined within the scope of the while loop.
D'oh worst of typos... should be "in your code" of corse ;-) 2014-08-26 15:13 GMT+02:00 Benedikt Ritter <[email protected]>: > Hello David, > > the problem you're encountering is a problem with scopes. A variable is > only available in the scope it was defined. In you're code the variable > values is defined within the scope of the while loop. This means, that the > variable is only defined between the curly brackets of the while loop. > > Your System.out statements try to access the values variable, which is no > longer accessible, since the flow of control has already left the scope it > was definied in (by finishing the iteration over the ResultSet). > > What you need to do is move the other System.out statements into the loop > like so: > > > while (rset.next()) > { > int values = rset.getInt("M_SecondsAtStatus"); > System.out.println(values); > > > // I am hoping to derive useful statistics from > my database, such as > // the following.this uses Jakarta Commons Math > System.out.println("min: " + > StatUtils.min(values)); > System.out.println("max: " + > StatUtils.max(values)); > System.out.println("mean: " + > StatUtils.mean(values)); > System.out.println("product: " + > StatUtils.product(values)); > System.out.println("sum: " + > StatUtils.sum(values)); > System.out.println("variance: " + > StatUtils.variance(values)); > } > > > This way statistics will be printed for each row in the result set. > > Regards, > Benedikt > > P.S.: Jakarta is an old name, that is not used any more. The name of the > project now is simple Apache Commons and you're using Apache Commons Math. > > > 2014-08-26 15:03 GMT+02:00 Kulpanowski, David <[email protected]>: > > Using jdbc I am querying my database of ambulance response times. My goal >> is to take the output and process it into statistics using Jakarta Commons >> Math library. So far I am successful in querying my database and outputting >> the response times to the console. My next step is to process this output >> statistically, such as mean, medians, mode, etc. This is where I am stuck. >> What I can't figure out is how to get my database output into a format for >> Commons Math to generate a statistical analysis. In other words, I have >> 100,000 ambulance responses, now I want to do more advanced statistical >> analysis with this data. >> Shown below is my code. >> >> package javaDatabase; >> >> import java.sql.*; >> import org.apache.commons.math3.stat.StatUtils; >> >> public class javaConnect4 >> { >> public static void main(String[] args) >> { >> Connection conn = null; >> Statement stmt = null; >> try >> { >> conn = DriverManager >> >> .getConnection("jdbc:sqlserver://myServerAddress;database=myDatabase;integratedsecurity=false;user=myUser;password=myPassword"); >> stmt = conn.createStatement(); >> String strSelect = "SELECT M_SecondsAtStatus FROM >> MManpower WHERE M_tTime > 'august 25, 2014' AND M_Code = 'USAR'"; >> >> ResultSet rset = stmt.executeQuery(strSelect); >> >> while (rset.next()) >> { >> int values = rset.getInt("M_SecondsAtStatus"); >> System.out.println(values); >> } >> >> // I am hoping to derive useful statistics from my >> database, such as >> // the following.this uses Jakarta Commons Math >> System.out.println("min: " + StatUtils.min(values)); >> System.out.println("max: " + StatUtils.max(values)); >> System.out.println("mean: " + StatUtils.mean(values)); >> System.out.println("product: " + >> StatUtils.product(values)); >> System.out.println("sum: " + StatUtils.sum(values)); >> System.out.println("variance: " + >> StatUtils.variance(values)); >> >> } catch (SQLException ex) >> { >> ex.printStackTrace(); >> } finally >> { >> try >> { >> if (stmt != null) >> stmt.close(); >> if (conn != null) >> conn.close(); >> } catch (SQLException ex) >> { >> ex.printStackTrace(); >> } >> } >> } >> } >> >> >> An error message pops up in Eclipse and the variable "values" is red >> underlined; "values cannot be resolved to a variable". >> I am not sure how to get this to work. >> I don't understand how to output my ambulance response times from the >> database into something Apache Commons math will understand. >> How can I get Apache Commons math to take the output from my database and >> generate a statistical result?. >> >> >> NOTES: >> 1.) I have cross-posted this question on StackOverflow.com but have not >> resolved the issue. >> 2.) I have verified that Apache Commons Math is registered in my project >> by hand coding a small array and using Commons Math to generate statistics. >> So Apache Math works and my database output goes to the console window, so >> it works also. But how do you get them to work together? >> 3.) I am a geographer, not a computer programmer. Believe me, you cannot >> make it simple enough. Please be explicit in your answers. >> >> David Kulpanowski >> Database Analyst >> Lee County EMS >> PO Box 398 >> Fort Myers, FL 33902-0398 >> 239-533-3962 >> [email protected] >> Longitude: -81.861486 >> Latitude: 26.528843 >> >> >> ________________________________ >> Please note: Florida has a very broad public records law. Most written >> communications to or from County Employees and officials regarding County >> business are public records available to the public and media upon request. >> Your email communication may be subject to public disclosure. >> >> Under Florida law, email addresses are public records. If you do not want >> your email address released in response to a public records request, do not >> send electronic mail to this entity. Instead, contact this office by phone >> or in writing. >> > > > > -- > http://people.apache.org/~britter/ > http://www.systemoutprintln.de/ > http://twitter.com/BenediktRitter > http://github.com/britter > -- http://people.apache.org/~britter/ http://www.systemoutprintln.de/ http://twitter.com/BenediktRitter http://github.com/britter
