Results 1 to 11 of 11
Like Tree5Likes
  • 1 Post By al_Marshy_1981
  • 2 Post By al_Marshy_1981
  • 1 Post By al_Marshy_1981
  • 1 Post By al_Marshy_1981

Thread: How to display data from database in JTextArea of User interface ?

  1. #1
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Question How to display data from database in JTextArea of User interface ?

    I have made a table in database which contains names and mobile numbers, now how can i show these data on a click of a button in a JTextArea of my Swing GUI ?
    PLEASE HELP IT'S URGENT

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: How to display data from database in JTextArea of User interface ?

    Are you able to retrieve data from the database already?
    adiotrox likes this.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: How to display data from database in JTextArea of User interface ?

    Please leave all mention of urgency out of your questions. Yes it's urgent, but to you alone. All who help here do so for free as volunteers, and it's not fair to the volunteers for you to pressure them for their help, nor for you to assume that your question was more important than any others. Your cooperation in this is greatly appreciated.

  4. #4
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Default Re: How to display data from database in JTextArea of User interface ?

    @moderator ok i will take care of this.

    @marshy i know only this part String url = "select name,mobile from contacts ;" so what is the method to display this in the textarea, my textarea name is "txtMessage"

  5. #5
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Default Re: How to display data from database in JTextArea of User interface ?

    @moderator Your cooperation in the solution of this problem is also greatly appreciated

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: How to display data from database in JTextArea of User interface ?

    Have you implemented a button with a listener. Not sure what you have so far. More information of what you do have working will help.
    .
    Fubarable and adiotrox like this.

  7. #7
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Default Re: How to display data from database in JTextArea of User interface ?

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String userid="root";
    String password="123456";
    String url="jdbc:mysql://localhost:3306/ediary";

    try
    {
    String sql = "select name from contacts ;" ;
    DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    Connection cn=DriverManager.getConnection(url,userid,password );
    PreparedStatement ps=cn.prepareStatement(sql);
    ResultSet rs=ps.executeQuery();
    jTextField1.setText(String.valueOf(rs));

    }catch(Exception ex)
    {
    System.out.println(ex);
    }


    // how to use ResultSet ???

  8. #8
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: How to display data from database in JTextArea of User interface ?

    adiotrox likes this.

  9. #9
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Default Re: How to display data from database in JTextArea of User interface ?

    i really appreciate for this notes on ResultSet and i promise i will study it but i have to show this work in few hours so please tell me the exact thing to do ?

  10. #10
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: How to display data from database in JTextArea of User interface ?

    The forum is for learning. A big part of programming is researching what you don't know and is a valuable skill. I can't just give you answers directly.

    I suggest you try your best to work out using result set and post any questions you have about it.
    Fubarable likes this.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: How to display data from database in JTextArea of User interface ?

    Quote Originally Posted by adiotrox View Post
    Java Code:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String userid="root";
        String password="123456";
        String url="jdbc:mysql://localhost:3306/ediary";
       
        try
            {
                String sql = "select name from contacts ;" ;
                DriverManager.registerDriver(new com.mysql.jdbc.Driver());
                Connection cn=DriverManager.getConnection(url,userid,password);
                PreparedStatement ps=cn.prepareStatement(sql);
                 ResultSet rs=ps.executeQuery();
                 jTextField1.setText(String.valueOf(rs));
              
            }catch(Exception ex)
            {
                System.out.println(ex);
            }

    // how to use ResultSet ???

    Quote Originally Posted by adiotrox View Post
    i really appreciate for this notes on ResultSet and i promise i will study it but i have to show this work in few hours so please tell me the exact thing to do ?
    It's actually not that difficult, and can be understood quickly by looking over this one page tutorial on how to use ResultSet data: Retrieving and Modifying Values from Result Sets. Notice how the code uses a while loop to loop through the result set, extracting information from it as it goes.
    This is all part of a multipage tutorial on doing database coding with Java, and you can find the rest of it here: Tutorial: JDBC Basics.


    Quote Originally Posted by adiotrox
    marshy i am hitting my head into this for a long and i promise i will study everything but i have a deadline to meet you know assignments grades please do help for now..
    No, that's not how it works around here. We are more than happy to help, but we try not to write your code for you.

    Best of luck.

Similar Threads

  1. Replies: 1
    Last Post: 01-25-2012, 05:10 PM
  2. problem in display the data in database using j2me
    By jamil in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-20-2011, 08:16 PM
  3. Database and user interface design
    By Implode in forum New To Java
    Replies: 12
    Last Post: 09-14-2009, 12:41 PM
  4. how to display data from oracle database?
    By deru4jesus in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 04-16-2009, 08:46 AM
  5. Replies: 0
    Last Post: 12-04-2008, 05:39 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
  •