Nervosa Posted November 22, 2014 Share Posted November 22, 2014 (edited) Hello! I've been having a lot of trouble getting the results back from my database using javascript. Basically my assignment was to store grades of a classmember - where a classmember is a certain ID - and get the average grade number back on the screen in a webbrowser - of a row. It should be working I'm just having trouble putting it out on the browser. public void Average(int Id, PrintWriter out) { String query ="select avg( math + phy + litr + chem + biolo)/5.0 from grades where Id=?"; try{ PreparedStatement preparedStmt = conn.prepareStatement(query); ResultSet rs = preparedStmt.executeQuery(); while (rs.next()) { String = Float.toString(rs.getFloat(1)); System.out.println(resultofgrades); out.print("Average of the student's grade" + resultofgrades); } }catch(Exception se) { se.printStackTrace(); } } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String str=request.getParameter("Id"); SQL2 s=new SQL2(); s.Average(Integer.parseInt(str),out); s.Close(); } I think this is all the relevant information to the question, if you need the entire code I can pastebin it but I do not think it's needed. I could make the SQL store the data I put in and print it on the browser. I checked my avg() in phpMyAdmin and it returns the correct value in there but not on my webbrowser screen, its blank. My guess what's wrong would be line 69: String = Float.toString(rs.getFloat(1)); But unfortunately I cannot seem to fix it. Hope you can help me out with this one: -nerv Edited November 22, 2014 by Nervosa Link to comment Share on other sites More sharing options...
niche Posted November 22, 2014 Share Posted November 22, 2014 have you done the ajax tutorial? http://www.w3schools.com/php/php_ajax_intro.asp Link to comment Share on other sites More sharing options...
davej Posted November 22, 2014 Share Posted November 22, 2014 I'm not sure if this is a Java Servlet question or a Javascript AJAX question. You might look at this example... http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now