• 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

Display the response data in a table rows format

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm writing a webapp where in there is a table that is to be generated based on the value entered in the textbox using Ajax. This data is actually pulled from the database. And below are my codes.

index.html


DataDAO.java



Controller.java



DBUtility.java



This code is working fine and giving me the correct output but the issue is with the way it is displayed.

In the textbox when I enter value as Sample1, The output that i get is as below.


But instead i want the above in different columns, like a table.

Previously I've worked with jstl, And the below is a best way to get the work done.



But I'm unable to know where am i supposed to place this block and how am i going to make a table.

Please let me know How can i do this. :banghead:

Thanks,
Marsoni
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are off to a good start. Your code looks well organized. There is room for improvement, especially in your DBUtility class, but we can talk about that later if you wish.

As for your table display, JSTL is not going to help you here because you are using Ajax. JSTL happens on the server, while Ajax is all on the client. By the time your JSTL page gets rendered for the client, it's just HTML. The server is done with it.

I do a lot of pages like this, and I use a jQuery plugin called DataTables. It's made for this very scenario. It will take your Ajax response and turn it into a table with pagination, search, sorting, etc. It's easy to get started with, but complex to master. But it's worth it. I use it a lot.
 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kevin,

Thanks for this suggestion.

J. Kevin Robbins wrote:You are off to a good start. Your code looks well organized. There is room for improvement, especially in your DBUtility class, but we can talk about that later if you wish.



Yes Please, I would love to know the flaws/improvement suggestions.

JI do a lot of pages like this, and I use a jQuery plugin called [url=http://datatables.net/ wrote:DataTables[/url]. It's made for this very scenario. It will take your Ajax response and turn it into a table with pagination, search, sorting, etc. It's easy to get started with, but complex to master. But it's worth it. I use it a lot.




Went through this. And this is very helpful. But I've some question. I'll better post it separately.

Thanks,
Marsoni

 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marsoni Hutao wrote:

J. Kevin Robbins wrote:You are off to a good start. Your code looks well organized. There is room for improvement, especially in your DBUtility class, but we can talk about that later if you wish.



Yes Please, I would love to know the flaws/improvement suggestions.


It's good that you've created a separate class to do the database connection. Many people put that code in the servlet where it doesn't belong. But using DriverManager is inefficient for a multi-user app. I sometimes use it for utility classes that run outside the web environment (cron jobs and so on), but for your web app you need to have a pool of connections that can be re-used.

Here is a document on using pooling with SQLServer. Actually setting up the pool depends on what web server you are running. If you are the server admin and need guidance on setting up the pool, we have other forums where you can get help with the specifics.

But for a moment, let's assume that your server is already setup with a connection pool and you just want to use it. I found an old, but good faq here. Another one from Oracle can be found here.

In short, DriverManager creates and then you must destroy the connection with every use. Creating database connections involves a lot of overhead for the server.

Using a pool, the connections are created at server startup and your DAO just grabs one, uses it, and then returns it to the pool for other objects to use. It's far more efficient.

[edit] One more thing that jumps out at me. Instead of using System.err, learn to use logging. I just use the logging included with Java. Many people like log4j but I've never been able to make it behave the way I want. I find java.util.logging to be much simpler to use.


 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic