Welcome to Dream.In.Code
Become a Java Expert!

Join 150,035 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,587 people online right now. Registration is fast and FREE... Join Now!




I'm trying to use a jcombobox to search data in my database

 
Reply to this topicStart new topic

I'm trying to use a jcombobox to search data in my database

dushi
15 Jun, 2008 - 03:07 PM
Post #1

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 39



Thanked: 1 times
My Contributions
Hello can someone look at my code and help me out here. I'm trying to search some saved data in my database using a jComboBox.
but when i clik on my search button it gives me this error: java.sql.SQLException: no value specified for parameter 1.

my other problem is in this line: jComboBox1.addActionListener(new Frame3_jComboBox1_actionPerformed(this)); i get the red error line under the Frame3_jComboBox1_actionPerformed. and the error i get is: cannot find symbol. does someone knows what that is. i've imported javax.swing but still i get the error


CODE

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Rectangle;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.sql.RowSet;
import com.sun.rowset.JdbcRowSetImpl;



/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Frame3 extends JFrame {
  protected boolean saveWasPressed;
  
  public Frame3() {
    try {
      jbInit();
    }
    catch (Exception exception) {
      exception.printStackTrace();


    }
  }

  private void jbInit() throws Exception {
    getContentPane().setLayout(null);
    jLabel1.setFont(new java.awt.Font("Tahoma", Font.BOLD, 15));
    jLabel1.setText("Computercentrum Universiteit van de Nederlandse Antillen");
    jLabel1.setBounds(new Rectangle(85, 46, 452, 24));
    jPanel1.setBounds(new Rectangle(17, 89, 610, 336));
    jPanel1.setLayout(null);
    jLabel3.setText("Cursus:");
    jLabel3.setBounds(new Rectangle(16, 33, 43, 23));
    jComboBox1.setBounds(new Rectangle(58, 32, 249, 22));
    jComboBox1.addActionListener(new Frame3_jComboBox1_actionPerformed(this));
    jComboBox1.addItem("Powerpoint Workshop");
    jComboBox1.addItem("Inleiding Web Design");
    jComboBox1.addItem("Advanced Web Design");
    jComboBox1.addItem("Windows 2000");
    jComboBox1.addItem("Inleiding Excel");
    jComboBox1.addItem("Advanced Excel");

    jTextArea1.setBounds(new Rectangle(19, 122, 433, 219));
    jLabel4.setText("Cursisten:");
    jLabel4.setBounds(new Rectangle(19, 93, 69, 14));
    jButton1.setBounds(new Rectangle(36, 460, 69, 21));
    jButton1.setText("CLOSE");
    jButton1.addActionListener(new Frame3_jButton1_actionAdapter(this));
    jButton2.setBounds(new Rectangle(322, 32, 73, 21));
    jButton2.setText("SEARCH");
    jButton2.addActionListener(new Frame3_jButton2_actionAdapter(this));
    this.getContentPane().add(jLabel1);
    this.getContentPane().add(jLabel2);
    this.getContentPane().add(jPanel1);
    this.getContentPane().add(jButton1);
    jPanel1.add(jLabel3);
    jPanel1.add(jComboBox1);
    jPanel1.add(jTextArea1);
    jPanel1.add(jLabel4);
    jPanel1.add(jButton2);
    jLabel2.setFont(new java.awt.Font("Tahoma", Font.BOLD, 19));
    jLabel2.setText("AANMELDINGSFORMULIER");
    jLabel2.setBounds(new Rectangle(158, 18, 271, 33));

  }

  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JPanel jPanel1 = new JPanel();
  JLabel jLabel3 = new JLabel();
  JComboBox jComboBox1 = new JComboBox();
  JTextArea jTextArea1 = new JTextArea();
  JLabel jLabel4 = new JLabel();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  private RowSet rs = new JdbcRowSetImpl();
  final String USERNAME = "root";
  final String PASSWORD = "waanje";

  public void jButton2_actionPerformed(ActionEvent e) {
    //load button

      try{
        Class.forName("com.mysql.jdbc.Driver");
        rs.setUrl("Jdbc:mysql://localhost/aanmeldingsformulier");
        rs.setUsername(USERNAME);
        rs.setPassword(PASSWORD);

        rs.setCommand("Select * From aanmeldingsformulier Where " +
          jComboBox1.getSelectedItem() + " =? ");

        rs.execute();

      //rs.setString(1, jTextArea1.getText());

      while(rs.next()) {
                 jTextArea1.append(rs.getString(1)+ " ") ;
                 jTextArea1.append("   ");
                 jTextArea1.append(rs.getString(3)+ " ");
                 jTextArea1.append(rs.getString(4)+ " ");
                 jTextArea1.append(rs.getString(5)+ " ");
                 jTextArea1.append(rs.getString(6)+ " ");
                 jTextArea1.append(rs.getString(7));

             }



    }

    catch (Exception ex) {
      JOptionPane.showMessageDialog(null, ex);
    }


  }

  public void jButton1_actionPerformed(ActionEvent e) {
    //cancel
        this.setVisible(false);
        saveWasPressed = false;
  }
  }


class Frame3_jButton1_actionAdapter
    implements ActionListener {
  private Frame3 adaptee;
  Frame3_jButton1_actionAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class Frame3_jButton2_actionAdapter
    implements ActionListener {
  private Frame3 adaptee;
  Frame3_jButton2_actionAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}


User is offlineProfile CardPM
+Quote Post

pbl
RE: I'm Trying To Use A Jcombobox To Search Data In My Database
15 Jun, 2008 - 03:44 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
You don't populate your JComboBox from the database... you populate with hardcoded String

CODE

    jComboBox1.addItem("Powerpoint Workshop");
    jComboBox1.addItem("Inleiding Web Design");
    jComboBox1.addItem("Advanced Web Design");
    jComboBox1.addItem("Windows 2000");
    jComboBox1.addItem("Inleiding Excel");
    jComboBox1.addItem("Advanced Excel");


and your method jButton1_actionPerformed in Frame3 does nothing

I think you will have to precise what your problem is
User is online!Profile CardPM
+Quote Post

dushi
RE: I'm Trying To Use A Jcombobox To Search Data In My Database
15 Jun, 2008 - 05:04 PM
Post #3

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 39



Thanked: 1 times
My Contributions
ok what this program has to do is. when i choose 1 item in the combobox for example i have chosen "Powerpoint Workshop" and i click on search (jbutton2) then i should see in my textarea everybody their names, adress etc that had taken the lessons from "Powerpoint Workshop"

but when i click on the search button it gives me the error :
java.sql.SQLException: no value specified for parameter 1.


the jButton1_actionPerformed in Frame3 has no fuction i only have 2 buttons on my form search(jButton2) and cancel(jbutton1)
User is offlineProfile CardPM
+Quote Post

mensahero
RE: I'm Trying To Use A Jcombobox To Search Data In My Database
16 Jun, 2008 - 04:43 AM
Post #4

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
CODE

  rs.setCommand("Select * From aanmeldingsformulier Where " +
          jComboBox1.getSelectedItem() + " =? ");


I think that's wrong. it should be something like .

CODE


........ WHERE subjects = jComboBox.getSelectedItem()


That's just an IDEA try and copy/ paste it. Believe me it wont work.
Recode your code to match the logic of my suggestion. That's just an opinion.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month