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:
But unfortunately I cannot seem to fix it.
Hope you can help me out with this one:
-nerv