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 ( {
                                    //Not working
                                    //Need to display the query results(there are 10 records from MS Access table)
                                    //in 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
Comment Utility
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

Comment Utility

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count7 challenge 12 67
array220 challenge 8 45
count11 challenge 6 47
Which is the latest version of Apache Tomcatl 3 35
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now