Solved

Passing parameters and displaying values

Posted on 2001-06-06
2
169 Views
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  {
                          jbInit();
                        }
                        catch(Exception ex) {
                          ex.printStackTrace();
                        }
                      }

                      private void jbInit() throws Exception {
                        jLabel1.setText("Code");
                        this.setLayout(xYLayout1);
                        jButton1.setText("Browser");
                        jButton1.addActionListener(new java.awt.event.ActionListener() {

                          public void actionPerformed(ActionEvent e) {
                            jButton1_actionPerformed(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" +
                                    "</ul>\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);
                                }
                            };
                            theLabel.setVerticalAlignment(SwingConstants.CENTER);
                            theLabel.setHorizontalAlignment(SwingConstants.CENTER);

                            JPanel rightPanel = new JPanel();
                            rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
                            rightPanel.setBorder(BorderFactory.createCompoundBorder(
                                            BorderFactory.createTitledBorder("A label with HTML"),
                                            BorderFactory.createEmptyBorder(10,10,10,10)));
                            rightPanel.add(theLabel);

                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
                            setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

                            //add(leftPanel);
                            add(Box.createRigidArea(new Dimension(10,0)));
                            add(rightPanel);
                        }

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

                            f.addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent e) {
                                    System.exit(0);
                                }
                            });

                            f.getContentPane().add(new HtmlDemo());
                            f.pack();
                            f.setVisible(true);
                        }

                     }
0
Comment
Question by:chandini
2 Comments
 
LVL 6

Accepted Solution

by:
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,

Dorothy
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
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.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Way to decrease size of apk file 9 110
servlet filter example 37 85
hibernate example for saving data 19 77
program arguments vs VM arguments 4 31
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 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