Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By camickr

Thread: problem in getting entire records to jtextarea from database

  1. #1
    Ashi is offline Member
    Join Date
    Jan 2012
    Location
    Pune ,Maharashtra
    Posts
    9
    Rep Power
    0

    Smile problem in getting entire records to jtextarea from database

    Sir,
    I am trying to retrieve data from MS Access database to JTextArea, we are creating one desktop application, for that whenever i am trying to retrieve data from database using while loop and print the data to jtextarea , the last record in the database get printed in the jtextarea instead of printing all the records. we use the code as-

    while(rs.next())
    {
    txt.setText(rs.getString("mrname")+"\t"+rs.getStri ng("drugs")+"\t"
    +rs.getString("company")+"\t"+rs.getString("quanti ty")+"\t"+rs.getString("category"));

    }
    We want to print all the records from the database. please provide us some solution to overcome that problem.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: problem in getting entire records to jtextarea from database

    That's because each time round that loop you are resetting the text value of the JTextArea.
    setText does not append.
    There's a method on JTextArea that does that...

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: problem in getting entire records to jtextarea from database

    A better solution would be to use a JTable. See: How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) for the basics and Table From Database « Java Tips Weblog for a specific solution.
    DarrylBurke likes this.

Similar Threads

  1. Replies: 4
    Last Post: 10-26-2011, 03:24 AM
  2. HighLighting an entire row of JtextArea
    By justbeller in forum AWT / Swing
    Replies: 3
    Last Post: 07-25-2011, 06:09 PM
  3. Cool Grid to manipulate with database records
    By leoleo4614 in forum AWT / Swing
    Replies: 2
    Last Post: 12-13-2008, 10:45 AM
  4. Replies: 0
    Last Post: 02-09-2008, 09:31 PM
  5. How to select/highlight an entire row in JTextArea
    By Valeriano in forum AWT / Swing
    Replies: 2
    Last Post: 05-28-2007, 12:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •