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 2 of 2

Thread: How do i show all the values in one window(JOptionPane)??

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How do i show all the values in one window(JOptionPane)??

    I have the following code:
    try
    {
    Class.forName("com.mysql.jdbc.Driver");
    conec = DriverManager.getConnection("jdbc:mysql://localhost/Inventory","root", "");
    est=conec.createStatement();
    res=est.executeQuery("SELECT id_client,name_client,date FROM client");
    [B]while(res.next())
    {
    idClient1=res.getString("id_client");
    NameClient=res.getString("name_client");
    Date1=res.getString("date");
    JOptionPane.showMessageDialog(null, "Document: "+idClient1+"\nName: "+NameClient+"\nDate: "+Date1);
    }[/B]}
    catch(ClassNotFoundException e)
    {
    e.printStackTrace();
    }
    catch(SQLException e)
    {
    e.printStackTrace();
    }
    the problem is that it shows the values but i have to click on accept to continue with the next one, How do i show all the values in one window?
    THANKS...


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How do i show all the values in one window(JOptionPane)??

    The easiest method is to create string that has all the information in it:

    // replace the bold stuff with this
    String toDisplay = "";
    while (res.next())
    {
         idClient1=res.getString("id_client");
         NameClient=res.getString("name_client");
         Date1=res.getString("date");
         toDisplay += "Document: "+idClient1+"\nName: "+NameClient+"\nDate: "+Date1 +"\n\n";
    }
    JOptionPane.showMessageDialog(null,toDisplay);

Similar Threads

  1. Using Icons in JOptionPane
    By Jchang504 in forum AWT / Java Swing
    Replies: 3
    Last Post: September 19th, 2014, 02:28 PM
  2. switch focus to another window
    By tuansoibk in forum AWT / Java Swing
    Replies: 1
    Last Post: November 13th, 2009, 02:02 PM
  3. Average program with array and loop and JOptionPane.
    By jeremykatz in forum AWT / Java Swing
    Replies: 6
    Last Post: October 25th, 2009, 02:33 PM
  4. JOptionPane Question/ Printing
    By 03EVOAWD in forum AWT / Java Swing
    Replies: 2
    Last Post: August 31st, 2009, 09:17 AM
  5. Navigating from one window to another
    By visharaddhavle83 in forum AWT / Java Swing
    Replies: 2
    Last Post: August 6th, 2009, 07:55 AM