[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

In Netbeans, how do I run an SQL Query through binding values to a component like JComboBox

Posted on 2009-02-21
7
Medium Priority
?
948 Views
Last Modified: 2013-11-23
Please view thee image. I can get a list of the database, but I really want to view just one item by querying for example "SELECT name FROM people", that way my combobox will get the exact value from the database without any extra information. I have used the procedure part of NetBeans from the database services but im sure ive seen a querying section which I can target from something like this.
sqlquerynetbeansbinding.JPG
0
Comment
Question by:namsu55
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 23703778
Are you not using TopLink?
0
 

Author Comment

by:namsu55
ID: 23703850
I tried the top link ill show you what it gives me:

desktopapplication1.Fighter[fighterid=2]

I would prefer to get something like 2 as that is the value of the field I am targeting.

But I dont actually know how to run a proper query inside netbeans for the binding part. If I had a query, then I could select certain values and only those would come up in the list.
0
 

Author Comment

by:namsu55
ID: 23703868
I could use an array or something to do the sql part for me couldnt I and then just load the combo box up with some values.
0
Technology Partners: 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!

 
LVL 15

Accepted Solution

by:
fsze88 earned 1500 total points
ID: 23703875
namsu55,
Actually, I answered on http://www.experts-exchange.com/Programming/Languages/Java/Q_24165773.html#23703727
Is is what you are asking?

private void jComboBox1_itemStateChanged(ItemEvent e) {
        String comboBoxValue;
        String Parameter;
        String[] pair;
       
        int beginIndex, endIndex;
        comboBoxValue = String.valueOf( jComboBox1.getItemAt(jComboBox1.getSelectedIndex() ));
        beginIndex = comboBoxValue.indexOf("[") +1;
        endIndex = comboBoxValue.indexOf("]");
        Parameter = comboBoxValue.substring(beginIndex,endIndex);
        System.out.println("Parameter : " + Parameter);
        pair = Parameter.split("=");
        System.out.println("value of figher : " + pair[1]);
//        System.out.println(e.toString() + e.getStateChange());
//        System.out.println(jComboBox1.getItemAt(jComboBox1.getSelectedIndex() )) ;
    }

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23703897
I'm not at all clear on what your required functionality is. If you show me what you think some *actual* sql would look like, that should clarify it
0
 
LVL 92

Expert Comment

by:objects
ID: 23703964
you can use a custom renderer (or just a toString()) to allow you to store any kind of data in your combos model.

So you could for example store the ids
or use a class that has the id and the string to display

let me know if you have any questions

0
 
LVL 92

Expert Comment

by:objects
ID: 23703971
so for example if you had a Data class that stored the details of each entry in the combo you would store the actual Database objects in the list model, and then to get selected you can use:

Database db = (Database) combo.getSelectedItem();
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

830 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