wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes Refresh chart in jsp according to MySQL database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Refresh chart in jsp according to MySQL database" Watch "Refresh chart in jsp according to MySQL database" New topic
Author

Refresh chart in jsp according to MySQL database

Meet Garvalia
Greenhorn

Joined: Mar 16, 2010
Posts: 7
I want to refresh the chart in jsp with MYSQL.
To draw bar chart i used following code:



Now, i want to refresh this chart every 30 secs. & change database in MySQL. How is it possible ? Any repl. vl b appreciated. This is urgent. Very nice Forum...Like it..Thank you...!
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

OK.. Are you going to host this application is a actual server. Anyway I'll stick with this code and try to give you a solution.

So, you are saving the generated chart by using "ChartUtilities.saveChartAsJPEG();" method, and displaying the saved image in a HTML file.

In that case, what you can do is simply making few AJAX requests from time to time. Here is an example with JQuery


Hope this helps.

Regards.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3051
    
  36

Welcome to JavaRanch.
Please note that accessing the database from a JSP is a really bad practice. Choose another model.
Please UseCodeTags when you post a code in future. It's unnecessarily hard to read the code otherwise.

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

Devaka Cooray wrote:
Please note that accessing the database from a JSP is a really bad practice.


Yeh that's why I asked if he is going to host this in an actual environment.. Also absolute path like "c:\s2s worksspace\s2sgateway\WebContent\chart.jpg" is not a good idea..
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

I think this topic is in the wrong forum (" JavaRanch » Forums » Products » Other Open Source Projects ")
Meet Garvalia
Greenhorn

Joined: Mar 16, 2010
Posts: 7
Thank you very much for your suggestions. I will apply and take care to post thread.


Actually i am going to develop real time stock update chart using Ajax+java script+My sql+java server pages+eclispe. I have created a table in My Sql, i want to change it automatically and update chart according to it. But i am a new to dis environment so, any suggestion or code will be appreciated. ie. how & which techs to use? This is Urgent. Thank you for your suggestions.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3051
    
  36

Meet Garvalia wrote:how & which techs to use?
Meet Garvalia wrote:i am going to develop real time stock update chart using Ajax+java script+My sql+java server pages+eclispe.

Have you answered your own question?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3051
    
  36

Ayoma Wijethunga wrote:I think this topic is in the wrong forum (" JavaRanch » Forums » Products » Other Open Source Projects ")

No, this topic has nothing to do with JSP. Let's continue the discussion here, for now.
Meet Garvalia
Greenhorn

Joined: Mar 16, 2010
Posts: 7
Devaka Cooray wrote:
Meet Garvalia wrote:how & which techs to use?
Meet Garvalia wrote:i am going to develop real time stock update chart using Ajax+java script+My sql+java server pages+eclispe.

Have you answered your own question?

I want suggestion using above combination which is a good practice?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3051
    
  36

Ayoma and I have already mentioned some good practices for your requirement.
You may also need to understand about how to apply some Design Patterns.
Have a look at this article
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

Yes. As Devaka mentioned, it is not clear what to say as a reply.

Anyway in this kind of a project you'll surely have to go for a client side technology. If you are more familiar with JavaScript, then no problem go ahead with JavaScript+ AJAX. Or else you can use JavaFX or similar technology. JSP seems to be a must, as you have already selected JSP as your server side language. Then MySQL really couples with Java and that sounds to be a good choice.

So your choice "Ajax+java script+My sql+java server pages" is a good one. Finally checkout Netbeans IDE. I'm a Netbeans fan at the moment


Regards.
Meet Garvalia
Greenhorn

Joined: Mar 16, 2010
Posts: 7
Thank you. I worked on the ajax as ayoma suggests. I am posting entire code.


I exported db and refresh the page so got it what i wanted to. Than you ayoma once again
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

Meet Garvalia wrote:Thank you ayoma once again


You are welcome Meet.. As I can see, one more change is required to make this work correctly. Your browser error log might be showing some errors at the moment.

Are you writing the AJAX part in JSP itself? Or do you have a JSP file and a HTML file separately for AJAX request.
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

Anyway, ignore that if code is working as same as you expected, with 30second auto refresh.

Regards...
Meet Garvalia
Greenhorn

Joined: Mar 16, 2010
Posts: 7
Ayoma Wijethunga wrote:
Meet Garvalia wrote:Thank you ayoma once again


You are welcome Meet.. As I can see, one more change is required to make this work correctly. Your browser error log might be showing some errors at the moment.

Are you writing the AJAX part in JSP itself? Or do you have a JSP file and a HTML file separately for AJAX request.


I am writing AJAX part in JSP itself.Which type of error your talking about ?

When i load new db it should be auto refreshed after 30secs ? or i have to refresh it ?
Rightnow i refresh it..then new db is seen in chart.

Thank you.
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

Ah ok... you asked for 30second auto refresh, didn't you? I send you the code for that. In your new code, you are not using AJAX part at all. It's just there and that trick won't be effective unless you put JSP and HTML in separate files. That's why we don't use JSP to access data base or for business logic.

Anyway let me just make it easy for you. Use this HTML instead of what you are using now. So you'll get 30second auto reload.



Meet Garvalia
Greenhorn

Joined: Mar 16, 2010
Posts: 7
You are right. I want to use Ajax but not gettin how ? do i put ajax script in different file than jsp ? then how can i debug it ? I am a new 2 dis... thank you..
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3051
    
  36

Meet Garvalia wrote:I am a new 2 dis

Pleas UseRealWords. You should read some Ajax tutorials like this one.
Meet Garvalia
Greenhorn

Joined: Mar 16, 2010
Posts: 7
Devaka Cooray wrote:
Meet Garvalia wrote:I am a new 2 dis

Pleas UseRealWords. You should read some Ajax tutorials like this one.

Ok..Thank you.
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

Yeh.. Devaka is correct.. There is no point of trying to implement AJAX if you are almost new. Try some articles. Most of all do some practice. Anyway this is how you should implement the code I added you few days before.

Code for http://localhost/Employee/chartex.jsp



Code for http://localhost/Employee/display.html


My advice - "Do NOT use this code unless you really understand it".. Go through tutorials and learn what is behind all this. Hope this helps.

Regards.
Jysh Reey
Greenhorn

Joined: Oct 10, 2011
Posts: 16
I tried executing this code with /jar files .. But am getting this stacktrace error --> java.lang.ClassNotFoundException: org.jfree.util.PublicCloneable.. My IDE does not show error in code anywhere. What might be the problem ...?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refresh chart in jsp according to MySQL database