Results 1 to 6 of 6
  1. #1
    zealman is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Multiple combobox

    i have form to customer fill it out.
    In that form, i have combobox which connect to my database to show product name.

    Java Code:
    teks=new JLabel("Car Name");
    textPerintah=new JTextField(15);
    teks1=new JLabel("Car Number");
    textPerintah1=new JTextField(15);
    teks2=new JLabel("Driver");
    textPerintah2=new JTextField(15);
    teks3=new JLabel("Date :");
    textPerintah3=new JTextField(15);
    teks4=new JLabel("Product Name :");
    	try {
    		Class.forName("com.mysql.jdbc.Driver");
    		Connection connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
    		Statement s=connect.createStatement();
    		String SQL=("SELECT product FROM storeproduct");
    		rs=s.executeQuery(SQL);
    		while (rs.next()) 
    		{
    			String product =rs.getString("product_name");
    			listBox.addItem(nama.trim());
    		}
    	    }
    	catch (Exception e)
    	    {
    		JOptionPane.showMessageDialog(null,"Failed to Connect to Database","Error Connection", JOptionPane.WARNING_MESSAGE);
    		System.exit(0);
    	    }
    
    listBox.addActionListener();
    teks5=new JLabel("Price");
    textPerintah5=new JTextField(15);
    If the customer have more than one product name, how can i make it?
    Can anybody help me. Thanks Before....

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default Re: Multiple combobox

    You select the colums "product" in your storeproduct table, but wants the "product_name" at the getString method? That`s not matching...it seems to be one of them is wrong.
    Have you debugged the code? Is the while loop entered?
    Maybe you have to use (just a suspicion):
    "SELECT product_name FROM storeproduct" ?
    Or tell us more about your table!

  3. #3
    zealman is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Multiple combobox

    Quote Originally Posted by eRaaaa View Post
    You select the colums "product" in your storeproduct table, but wants the "product_name" at the getString method? That`s not matching...it seems to be one of them is wrong.
    Have you debugged the code? Is the while loop entered?
    Maybe you have to use (just a suspicion):
    "SELECT product_name FROM storeproduct" ?
    Or tell us more about your table!
    upss..sorry...
    this is the correct code and i already debugged...
    Java Code:
    teks=new JLabel("Car Name");
    textPerintah=new JTextField(15);
    teks1=new JLabel("Car Number");
    textPerintah1=new JTextField(15);
    teks2=new JLabel("Driver");
    textPerintah2=new JTextField(15);
    teks3=new JLabel("Date :");
    textPerintah3=new JTextField(15);
    teks4=new JLabel("Product Name :");
    	try {
    		Class.forName("com.mysql.jdbc.Driver");
    		Connection connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
    		Statement s=connect.createStatement();
    		String SQL=("SELECT product FROM storeproduct");
    		rs=s.executeQuery(SQL);
    		while (rs.next()) 
    		{
    			String product =rs.getString("product");
    			listBox.addItem(nama.trim());
    		}
    	    }
    	catch (Exception e)
    	    {
    		JOptionPane.showMessageDialog(null,"Failed to Connect to Database","Error Connection", JOptionPane.WARNING_MESSAGE);
    		System.exit(0);
    	    }
    
    listBox.addActionListener();
    teks5=new JLabel("Price");
    textPerintah5=new JTextField(15);
    Can u help me, sir?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Multiple combobox

    Sorry, not sure what your problem is.
    What should it be doing?
    That code can't be compiling, surely?
    I can see at least one error in there witht he addActionListener.
    Please do not ask for code as refusal often offends.

  5. #5
    zealman is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Multiple combobox

    Quote Originally Posted by Tolls View Post
    Sorry, not sure what your problem is.
    What should it be doing?
    That code can't be compiling, surely?
    I can see at least one error in there witht he addActionListener.
    If the customer have more than one product name, how can i make it?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Multiple combobox

    They can, assuming that's a default JList.
    It defaults (if I remember) to multi select.

    (And that code still doesn't compile).
    Please do not ask for code as refusal often offends.

Similar Threads

  1. One process open multiple threads on multiple CPUs
    By kfcnhl in forum Threads and Synchronization
    Replies: 2
    Last Post: 12-12-2011, 08:27 AM
  2. How to create Multiple Combobox Vertically.
    By Khan05 in forum New To Java
    Replies: 6
    Last Post: 08-06-2011, 07:54 AM
  3. multiple Data from Jsp that having same name of multiple input tage to servlet
    By rahul9323.2007@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 07-29-2011, 01:00 PM
  4. combobox
    By dina in forum AWT / Swing
    Replies: 7
    Last Post: 05-11-2011, 05:31 PM
  5. Multiple ComboBox - Reading Text
    By jorgelex008 in forum AWT / Swing
    Replies: 6
    Last Post: 01-04-2010, 11:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •