Results 1 to 6 of 6
- 10-06-2011, 04:17 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 4
- Rep Power
- 0
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.
- 10-06-2011, 02:58 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 4
- Rep Power
- 0
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());
}
}
}
- 10-06-2011, 03:14 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 4
- Rep Power
- 0
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?
- 10-06-2011, 03:50 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Java JDBC - Display Multiple Query Results in one GUI
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.
- 10-06-2011, 03:58 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 4
- Rep Power
- 0
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);
- 10-06-2011, 05:03 PM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
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
-
Returning multiple results in JDBC
By mDennis10 in forum New To JavaReplies: 7Last Post: 08-23-2011, 03:38 PM -
Having problem on retriving results from a query
By mike_ledis in forum JDBCReplies: 4Last Post: 05-18-2011, 09:21 AM -
how to take query results to a jlist!!
By themburu in forum JDBCReplies: 1Last Post: 06-07-2008, 10:51 AM -
how to take query results to a jlist!!
By themburu in forum New To JavaReplies: 3Last Post: 06-07-2008, 10:45 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks