Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:39:24+00:00 2026-05-31T14:39:24+00:00

I have a servlet that connects to the mysql database, the resultset gets some

  • 0

I have a servlet that connects to the mysql database, the resultset gets some values from a column with numerical values, these values go in a google link that produces a chart as an image as a result… this is my code for it :

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            //OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
            //System.out.println("SensorGraph");

            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            //sensor Id
            String id = request.getParameter("id");
            // limit in the query
            String limit = request.getParameter("limit");
            DatabaseConnection db_connection =  new DatabaseConnection()._instance;
            Connection connection = null;
            try {
                connection = db_connection.getConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            Statement statement;
            ResultSet resultSet;
            try {
                statement = (Statement) connection.createStatement();
                resultSet = statement.executeQuery("select * from Sensor_Entries order by EntryTime asc limit 100");
                String values = "";
                while(resultSet.next()) {
                    String value = resultSet.getString("EntryValue");
                    values += (value) + ",";
                }
                //System.out.println(values);
                values = values.substring(0, values.length()-1);


                String image = "http://chart.apis.google.com/chart?" +
                        "chxr=0,0,1000" +
                        "&chxs=0,676767,12.167,-0.5,l,676767" +
                        "&chxt=y" +
                        "&chs=1000x300" +
                        "&cht=ls" +
                        "&chco=3D7930" +
                        "&chds=0,1000" +
                        "&chd=t:" + values+
                        "&chg=14.3,-1,1,1" +
                        "&chls=2,4,0" +
                        "&chma=0,6%7C3" +
                        "&chm=B,C5D4B5BB,0,0,0" +
                        "&chtt=Sensor+Values" +
                        "&chts=F00D0D,14.5";

                //if(request.getParameter("img") != null)
                    out.write("<img src=\"" + image + "\" />");

                statement = (Statement) connection.createStatement();
                /*resultSet = statement.executeQuery("select * from Sensors join " +
                        "(select * from Sensor_Entries order by EntryTime desc) as Sensor_Entries on " +
                        "(Sensors.SensorID=Sensor_Entries.SensorID) where Sensors.SensorID='" + id + "' " +
                        "group by Sensors.SensorID;");*/

                resultSet = statement.executeQuery("select * from Sensors join " +
                        "(select * from Sensor_Entries order by EntryTime desc) as Sensor_Entries on " +
                        "(Sensors.SensorID=Sensor_Entries.SensorID)"); /*where Sensors.SensorID='" + id + "' " +
                        "group by Sensors.SensorID;");*/

                ResultSetMetaData resultSetMetaData = (ResultSetMetaData) resultSet.getMetaData();
                if(resultSet.next()) {
                    out.write("<table>");
                    for(int i = 1; i < resultSetMetaData.getColumnCount() + 1; i++) {
                        String value = "";
                        int type = resultSetMetaData.getColumnType(i);
                        if(type == Types.INTEGER || type == Types.TINYINT) {
                            value = "" + resultSet.getInt(i);
                        } else if(type == Types.VARCHAR) {
                            value = resultSet.getString(i);
                        } else if(type == Types.TIMESTAMP) {
                            value = resultSet.getTimestamp(i).toString();
                        } else if(type == Types.DOUBLE) {
                            value = "" + resultSet.getDouble(i);
                        }

                        //out.write("<tr>" +
                               // "<td>" + resultSetMetaData.getColumnName(i) + "</td>" +
                               // "<td>" + value + "</td>" +
                                //"</tr>");
                    }
                    out.write("</table></center>");
                }
                else
                    out.write(image);
                out.flush();
                out.close();
            } catch (SQLException ignored) { ignored.printStackTrace();  }
        }

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);

}

HOW CAN i GET A NEW GRAPH EVERY 10 SECONDS PROVIDING THAT I KNOW THAT THE VALUES WILL CHANGE IN THE COLUMN WITH VALUES? … PLEASE HELP ME …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:39:25+00:00Added an answer on May 31, 2026 at 2:39 pm

    You cannot flush a ServletOutputStream multiple times. It will complain. You’ll have to create a background processing thread with some sort of identifier, and use ajax from the client side to get the current set of calculations and render them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java servlet that connects to a MySQL database. And it is
I have this java servlet that grabs information from a form, I need to
I'm working on an application. I have a servlet (writeDataBase.class) that writes some information
I have a servlet that request a geolocation from another server using an http
I have a servlet that receives some POST data. Because this data is x-www-form-urlencoded,
I have one Servlet that does insertion into my database. This is working fine.
I have a servlet that is used for many different actions, used in the
I have a servlet that I would like to run within ColdFusion MX 7.
Under JBoss 4.0.1SP1, I have a servlet that makes multiple, concurrent calls to web
I have installed a servlet (solr) that requires that I set the variable solr.solr.home

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.