• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating Charts in Applets using Data from Database

 
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i am creating Pie chart and Bar graphs using the data from the database. For that Applets are designed which draw Pie chart and Bar graph for me. now i have to pass data from database tables as parameters. Can anybody suggest me how do i do this.

my html file that calls applet is



As you can see i tried passing the values from javascript (where javascript calls a servlet and get database value) . But by the time servlet fetches data from database the applet code runs and calls Pie3D.class and dispaly error as &{amount1} and &{amount2} do not have values.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While there are intricate and brittle ways of using JavaScript for this, those wouldn't work when using PARAM tags. The easiest way would be to make the HTML page a JSP page, and in the JSP page to use a backing bean that pulls in the values from the DB, and so can populate the PARAM tags right when they are generated. That's much more straightforward than doing anything after the page has been served.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. Can i add database connection in my applet and put the data directly into getParameter() inside the applet.
And i am currently trying that but the pie being displayed is of one color ... database data has got no effect on the Pie display.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's generally considered bad design for applets to connect directly to databases for security reasons (and if you were to go that route, then getParameter would not be part of the solution).

We can't comment on what might be going wrong with your current approach since we don't know how that works.

If it's really just two values that you need, then I think that the approach I mentioned in my previous post would work best.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to design beans now, which i did not do before.



where do i add setters and getters and how do i link the applet parameters to these setters and getters.

Please suggets me.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this class supposed to be used as part of the client (the applet) or as part of the server (the web app)?
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My scenario is to show daily sales,collection,profit,loss in the form of Pie chart and bar graph, and the figures of these are stored in a table that gets populated everyday .
Therefore i am trying to get these values from that table as a parameter to the applet.

and yes this is part of server.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that class runs on the server, then your JSP now needs to use it; check out the jsp:useBean directive. The bean also needs to expose all values that you need to embed in the HTML page through public getter methods. Any decent JSP tutorial covers these steps (in case you haven't used JSP beans before).
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I added the getters and setters in the same bean .. as it should be the getters and setters are having the last row fetched from the table... how do i get all the rows fetched in my jsp ... in jsp i am using useBEan and getProperty tag and it fetched me last row from the table.

Can you please suggest me some JSP tutorial.

Thanks for your time.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
finally i am able to pass the parameters to the applet param tag



But here the number of parameters are specific.
Suppose 3 more rows get added into database then i need to change my bean class which has all the values exposed that get embedded in the html page.
how can i make my bean,param tags in the html dynamic so that if more number of rows get added in table then i need not change the bean, html page.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can add a parameter that indicates how many values you're passing along. Then the applet can iterate from 1 to that number to retrieve all parameters and their values:
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how do i make bean dynamic .. so that it adds the setters and getters on its own based on the rows fetched from database.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll have to make your code independent of the actual names:

The JSP would then iterate over all entries in the map and create PARAM tags accordingly.
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic