Solved

Passing parameters and displaying values

Posted on 2001-06-06
2
167 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 109
Java Server Faces parameter pass? 6 50
expectj telnet failing 5 37
Chrome and Firefox Java 5 34
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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…

831 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