• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Passing parameters and displaying values

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
chandini
Asked:
chandini
1 Solution
 
dorothy2Commented:
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
 
sudhakar_koundinyaCommented:


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

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now