Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Fetch Data and Render

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Fetch Data and Render

    Hi All,
    I am new to Java. I am able to connect to SQL Server DB, fetch data. Can someone help me how do I render the data on the UI. Meaning, creating a html table kind and displaying the data.

    Thanks.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Fetch Data and Render

    This fully depends upon the data, and how you wish to render. You indicate 'html table' - suggesting this is more of an html question than a java question. If you wish to use something like java Swing, I recommend reading: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fetch Data and Render

    Quote Originally Posted by copeg View Post
    This fully depends upon the data, and how you wish to render. You indicate 'html table' - suggesting this is more of an html question than a java question. If you wish to use something like java Swing, I recommend reading: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    Well, table meaning, just displaying rows and columns in a tabular format. Data is pretty straight forward with 5 columns and 10 rows. I wanted to display in a simple table rather than just displaying it.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Fetch Data and Render

    Quote Originally Posted by bheemar View Post
    Well, table meaning, just displaying rows and columns in a tabular format. Data is pretty straight forward with 5 columns and 10 rows. I wanted to display in a simple table rather than just displaying it.
    That doesn't clarify things much...you could display a table in a webpage, in a program with a graphical user interface, on the command line, save it in a file that can be read by another program (eg excel)...I recommend clarifying exactly how you wish to display your data, as that will help us point you in the right direction (rather than guessing what your needs are)

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fetch Data and Render

    Quote Originally Posted by copeg View Post
    That doesn't clarify things much...you could display a table in a webpage, in a program with a graphical user interface, on the command line, save it in a file that can be read by another program (eg excel)...I recommend clarifying exactly how you wish to display your data, as that will help us point you in the right direction (rather than guessing what your needs are)
    Thanks for your quick response. I want to create a webpage and display the data (GUI) similar to Grid in ASP.NET.

  6. #6
    Junior Member
    Join Date
    Feb 2014
    Location
    Finland
    Posts
    25
    My Mood
    Bored
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Fetch Data and Render

    Are you using Java EE with perhaps some framework(s?) to create the front end and then deploying a full web application or do you just want to output the data to a .html file?

    Anyway, i think this might be the wrong section of the forum if i understood correctly and you have already handled the fetching of your data from the DB?

    But what ever your plan is, i think the basic principle would be that you manage the data you dug from the db to some kind of model objects. For example if you got 10 rows from Person table, you want to make 10 Person objects that correspond to the db table and pass a list containing those Person-objects to a repeater of some kind. What that repeater is, depends on the fist question that copeg also asked: What do you want to do? .
    If you want just to outstream the data to html file you might want to write your own handler. Maybe something as simple as some filewriter implementation that writes the HTML-stuff to a file

    For example: You made Person -object from each of your query result rows, and packed em to an ArrayList<Person> listOfPersons.

    Then you write the non-repeating part of the html file, then go throught the lsit of objects ( "repeat" ) and write each line to the file as the html table rows, and end the file.
    Something in these lines:
     
    //... something in the lines of PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("thehtmlfile.html")));
     
    pw.println("<html><head/><body><table>"); // the upper side of the file
     
    //then loop through the person objects which have the html row in their toString method. 
    for ( Person currentPerson : listOfPersons )
    pw.println(currentPerson);
     
    // rest of the html file
    pw.println("</table></body></html>");
    pw.close();

    The Person's toString could be something like
    public String toString() {
    return "<tr><td>" + firstName +"</td><td>" + lastName + "</td></tr>";
    }

    Note that this is not a proper way of doing things by any imagination, but i hope you got the idea. Also read about the MVC design pattern.

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fetch Data and Render

    Quote Originally Posted by Wizand View Post
    Are you using Java EE with perhaps some framework(s?) to create the front end and then deploying a full web application or do you just want to output the data to a .html file?

    Anyway, i think this might be the wrong section of the forum if i understood correctly and you have already handled the fetching of your data from the DB?

    But what ever your plan is, i think the basic principle would be that you manage the data you dug from the db to some kind of model objects. For example if you got 10 rows from Person table, you want to make 10 Person objects that correspond to the db table and pass a list containing those Person-objects to a repeater of some kind. What that repeater is, depends on the fist question that copeg also asked: What do you want to do? .
    If you want just to outstream the data to html file you might want to write your own handler. Maybe something as simple as some filewriter implementation that writes the HTML-stuff to a file

    For example: You made Person -object from each of your query result rows, and packed em to an ArrayList<Person> listOfPersons.

    Then you write the non-repeating part of the html file, then go throught the lsit of objects ( "repeat" ) and write each line to the file as the html table rows, and end the file.
    Something in these lines:
     
    //... something in the lines of PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("thehtmlfile.html")));
     
    pw.println("<html><head/><body><table>"); // the upper side of the file
     
    //then loop through the person objects which have the html row in their toString method. 
    for ( Person currentPerson : listOfPersons )
    pw.println(currentPerson);
     
    // rest of the html file
    pw.println("</table></body></html>");
    pw.close();

    The Person's toString could be something like
    public String toString() {
    return "<tr><td>" + firstName +"</td><td>" + lastName + "</td></tr>";
    }

    Note that this is not a proper way of doing things by any imagination, but i hope you got the idea. Also read about the MVC design pattern.
    Thanks for your reply. I am trying to create a Java web page, create a html table within the page and display data. Please see the attachment.

    Regards.
    Attached Images Attached Images

Similar Threads

  1. how to fetch data from MySQL into textarea...
    By Ravi Raj in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 7th, 2013, 05:18 AM
  2. JDialog Failing to Render...
    By snowguy13 in forum AWT / Java Swing
    Replies: 2
    Last Post: April 7th, 2012, 11:55 AM
  3. Replies: 3
    Last Post: September 1st, 2011, 10:49 AM
  4. Render data on next page
    By Rajat in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 25th, 2011, 09:46 AM
  5. How to fetch integer data from excel
    By nehakuls in forum JDBC & Databases
    Replies: 5
    Last Post: May 14th, 2010, 01:44 AM