• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating browser gui for mysql data  RSS feed

 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, if you have read any of my previous posts then you know what i a working on. I have created a DAO and servlet to call mysql data from my DB and then it renders in a table in the console. However, I would really like to get it in a table in html in the browser. I have heard there are a few ways of doing this. I have looked a it at hardcoding it into the servlet or DAO but it seems very messy. I have also researched JSF's and ResultSetMetaData but I cannot find a way to implement them into my project. I would just like advice on which you believe would fit my project best and where i should put them in my code.

My DAO:





My Servlet:






Thank you.






EDIT:

I do know have ResultSetMetaData works but I can't think of how i would put it in html table. Would I assign variables to the data received and then use those.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there are numerous generic open source web apps for browsing DBs out there, so my first question would be: why write your own? Or should this do something specific for your data, and not just be a passive browser?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not 100% clear I understand your post but I think you're saying why would i want to display it. This is just a step in my goal of creating a DB management utility web application. Did i interpret it correctly?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite, I can see why you'd want such a tool. The question is more like: why do you want to write it yourself instead of using an existing tool? What would it do that a generic DB browser can't do? Not to mention tools like phpMyAdmin.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no real purpose. I just want to do it for fun.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have now gained data from columns into variabes using ResultSetMetaData and I want to out.print the html table with these. However, it says "out cannot be resolved". What is causing this. I have looked around but only found that it should be working. Do you think there is something i'm missing.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfectly valid reason :-). If this is just for this one query, then I don't think you need the ResultsetMetaData at all - because you already know all the involved data types. You could just emit HTML from within the servlet, or -much better- create an array of KeyInfo objects that you can then pass to a JSP that creates the HTML.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have now tried putting it in a try/catch but out can still not be resolved.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get a PrintWriter via the HttpServletResponse's getWriter() method. That's where you would write the HTML to.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
out is not defined anywhere in the Java code you posted, that's the reason.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thank you. I will work on that now.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i create the PrintWriter in the DAO or just in the Servlet? I tried both but neither are working. I may have done it wrong because I am not certain how to get it to print to Tomcat server. I assumed it was PrintWriter pr = PrintWriter(CS.something); The issue is I don't know what the something is and i cant find it anywhere.

EDIT: I think i have worked out now that it cant be in DAO and the 'something' is toString(). However, even with the DAO object I cant access the connection in my Servlet.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're on the wrong track. No toString() method should be involved. At the least, that would be very unusual. Something like this:

Obviously, there's still a lot of HTML missing, and it makes assumptions of how the DAO makes the data available, but it's one way it might happen.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see. Thanks for clarifying.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!