Results 1 to 6 of 6
  1. #1
    nov072008 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default Java JDBC - Display Multiple Query Results in one GUI

    Heya this is my first post. I'm using java in Eclipse and trying to create a GUI interface between a SQL 2005 Database. I can get everything to work aside from getting the joptionpane.showdialogmessage GUI to show all of the results. I can't paste my code right now, because my vpn isn't working.

    I have a user input part of the query for the where selection which returns 5-6 rows. Instead of showing all rows within the same gui; it displays the first row and allows you to click 'Ok' and the next gui pops up with the next row and so on.

    Tomorrow I will post the code if that is needed.

  2. #2
    nov072008 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default Re: Java JDBC - Display Multiple Query Results in one GUI

    Please Help or suggestions


    package mapcom.qualified;



    import java.sql.*;
    import javax.swing.JOptionPane;

    class ExecuteSqlQuery {

    public static void main (String[] args) {
    try {


    String url = "jdbc:sqlserver://local;databaseName=local;integratedSecurity=true";
    Connection conn = DriverManager.getConnection(url,"","");
    Statement stmt = conn.createStatement();
    ResultSet rs;
    String fn = JOptionPane.showInputDialog ("Enter Slid Location ID:");

    int custslid;


    custslid = Integer.parseInt(fn);
    rs = stmt.executeQuery("select distinct structures.id a, smquals.servtypelink as b from structures, smquals, smservlocs where structures.id = smservlocs.servloclink and smservlocs.id = smquals.servloclink and structures.slid ="+custslid);

    while ( rs.next() ) {

    String lastname = rs.getString("b");
    String id = rs.getString("a");



    {JOptionPane.showMessageDialog(null, "The ID is: " +id+"\n The Last Name is: " +lastname, "Services Structure is Qualified for:" +id , JOptionPane.PLAIN_MESSAGE);




    }
    }










    conn.close();
    } catch (Exception e) {
    System.err.println("Got an exception! ");
    System.err.println(e.getMessage());
    }

    }

    }

  3. #3
    nov072008 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default Re: Java JDBC - Display Multiple Query Results in one GUI

    Should I be using a Jframe and have the results come across as Jlabels instead?

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Java JDBC - Display Multiple Query Results in one GUI

    Quote Originally Posted by nov072008 View Post
    Should I be using a Jframe and have the results come across as Jlabels instead?
    You can have whatever you wish...to add all the results to a JOptionPane, append the results together (using a StringBuilder or string addition) as you loop over them, then show the Dialog after the loop is complete. To add to a custom JFrame, you might consider adding the results to an ArrayList, then display in a JTable.

  5. #5
    nov072008 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default Re: Java JDBC - Display Multiple Query Results in one GUI

    So in my code a stringbuilder would look something like this?


    String lastname = rs.getString("b");
    String id = rs.getString("a");

    StringBuilder aaa = new StringBuilder(lastname + id);

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Java JDBC - Display Multiple Query Results in one GUI

    For information on the String and StringBuilder classes, see Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)

Similar Threads

  1. Returning multiple results in JDBC
    By mDennis10 in forum New To Java
    Replies: 7
    Last Post: 08-23-2011, 03:38 PM
  2. Replies: 4
    Last Post: 05-18-2011, 09:21 AM
  3. how to take query results to a jlist!!
    By themburu in forum JDBC
    Replies: 1
    Last Post: 06-07-2008, 10:51 AM
  4. how to take query results to a jlist!!
    By themburu in forum New To Java
    Replies: 3
    Last Post: 06-07-2008, 10:45 AM

Posting Permissions

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