Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Passing parameters and displaying values

Posted on 2001-06-06
Last Modified: 2010-05-18
Hi Friends,

I am having problem with my Java codes. I am supposed to do a query and pass the query results to a second Java File to display the results in a tabular HTML format. My query is done at the button in First Java file and it is supposed to retrieve records from a field in Ms Access and display in HTML format in Java 2 file.  Please help if you can. Thank you:).

First File Codes
                     package untitled1;
                     import java.awt.*;
                     import javax.swing.*;
                     import com.borland.jbcl.layout.*;
                     import java.awt.event.*;

                     public class Panel1 extends JPanel {
                      JLabel jLabel1 = new JLabel();
                      XYLayout xYLayout1 = new XYLayout();
                      JTextField jTextField1 = new JTextField();
                      JButton jButton1 = new JButton();

                      public Panel1() {
                        try  {
                        catch(Exception ex) {

                      private void jbInit() throws Exception {
                        jButton1.addActionListener(new java.awt.event.ActionListener() {

                          public void actionPerformed(ActionEvent e) {
                        this.add(jTextField1, new XYConstraints(171, 121, 137, 56));
                        this.add(jLabel1, new XYConstraints(104, 118, 42, 52));
                        this.add(jButton1, new XYConstraints(139, 223, 119, 36));

                      void jButton1_actionPerformed(ActionEvent e) {
                        String query = "SELECT description  " +
                                                   "FROM table " +
                                                   "WHERE code = '" +
                                                          jTextField1.getText() + "'";
                                    Statement statement = Gconnect.createStatement();
                                    ResultSet rs = statement.executeQuery(query);
                                    while (rs.next()) {
                                    //Not working
                                    //Need to display the query results(there are 10 records from MS Access table)
                                    //in HtmlDemo.java file's label in a table format as well.

                     /****************2nd file*************************/
                     import javax.swing.*;
                     import java.awt.*;
                     import java.awt.event.*;

                     public class HtmlDemo extends JPanel {

                        JLabel theLabel;
                        //JTextArea htmlTextArea;

                        public HtmlDemo() {
                            String initialText = "<html>\n" +
                                    "Display test:\n" +
                                    "<ul>\n" +
                                    "<table border=1 width=40%>" +
                                      "<tr>" +
                                        "<td width=50%>code</td>" +
                                        "<td width=50%>description</td>" +
                                      "</tr>" +
                                      "<tr>" +
                                        "<td width=50%>result</td>" +
                                        "<td width=50%>result</td>" +
                                      "</tr>" +
                                      "<tr>" +
                                        "<td width=50%>result</td>" +
                                        "<td width=50%>result</td>" +
                                      "</tr>" +
                                    "</table>\n" +

                            theLabel = new JLabel(initialText) {

                                public Dimension getPreferredSize() {
                                    return new Dimension(200, 200);
                                public Dimension getMinimumSize() {
                                    return new Dimension(200, 200);
                                public Dimension getMaximumSize() {
                                    return new Dimension(200, 200);

                            JPanel rightPanel = new JPanel();
                            rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
                                            BorderFactory.createTitledBorder("A label with HTML"),

                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

                            add(Box.createRigidArea(new Dimension(10,0)));

                        public static void main(String args[]) {
                            JFrame f = new JFrame("HtmlDemo");

                            f.addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent e) {

                            f.getContentPane().add(new HtmlDemo());

Question by:chandini

Accepted Solution

dorothy2 earned 50 total points
ID: 6161616
You have a variety of things which would cause your code to fail. You need to use JDBC, and it looks like you are unfamiliar with the JDBC protocols because you don't have 'import java.sql.*', and you are not setting up a connection to the database before you try to execute your query. There are some on-line tutorials about JDBC, or any basic Java reference book should have a section on JDBC. Also, if you are using Borland's UI classes you must be using JBuilder. JBuilder has a bare-bones JDBC app in Chapter 2 of their Developer's Guide for JDataStore 4.

You are using a standalone Java application and AWT/SWING to generate HTML. Why wouldn't you use servlets or Java Server Pages?

I think I would focus on either the user interface or the database calls and get one working, rather than trying to tackle both at the same time.

Good luck,

LVL 14

Expert Comment

ID: 8898946

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-- Points to dorothy2

Please leave any comments here within the next seven days.
EE Cleanup Volunteer
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 77
reverse digits of a number using for loop 5 52
How to convert from xls to xlsx using java 7 55
Java: The Public Class Main 4 32
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question