I am trying to use a combo to generate query on the JTable.

package tables; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import javax.swing.*; import javax.swing.JFrame; import javax.swing.table.DefaultTableModel; public class Dynamictable extends JFrame {       public JComboBox combo;   JLabel labelz;   JPanel p1,scrollpanel;   String query;     public Dynamictable()     {                 p1 = new JPanel();         try{         JFrame frame = new JFrame("This is my table");         frame.addWindowListener(new WindowAdapter() {         public void windowClosing(WindowEvent e)         {             System.exit(0);         }         });         //Initializing the panel to contain the combox         p1 = new JPanel();         scrollpanel = new JPanel();         labelz = new JLabel("Select Matric Number or All -");               Combodata j = new Combodata();         Vector com =  j.setdata();         com.addElement("All");           String com1[] = new String[com.size()];         for(int i=0; i<com.size(); i++){       com1[i] = com.elementAt(i).toString();       combo = new JComboBox(com1);       System.out.println(com1);
p1.add(labelz);
p1.add(combo);
String data1,data2,data3,data4;
data1 = null;
data2 = null;
data3 = null;
data4 = null;
DefaultTableModel tablemodel = new DefaultTableModel();
//adding the connection into the datasource
String url = "jdbc:odbc:mydata";
Connection con = DriverManager.getConnection(url);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement stat = con.createStatement();
query = "select * from Firstsemester;";
Myquery q = new Myquery();
q.sendQuery(combo);
ResultSet result = stat.executeQuery(query);
//while(result.next()){rows++;}
tablemodel.addColumn("Matric Number");
tablemodel.addColumn("Course");
tablemodel.addColumn("Point");
tablemodel.addColumn("Unit");
//Collecting the values into the vector
while(result.next())
Vector tabledata = new Vector();
data1 = result.getString("Matric_Number");
tabledata.addElement(data1);
data2 = result.getString("Courses");
tabledata.addElement(data2);
data3 = result.getString("Points");
tabledata.addElement(data3);
data4 = result.getString("Units");
tabledata.addElement(data4);
//getting rows
tablemodel.addRow(tabledata);
JTable table = new JTable(tablemodel);
JScrollPane scroll = new JScrollPane(table);
table.getParent().setSize(new Dimension(500,100));
scrollpanel.add(scroll);
scrollpanel.setSize(500,100);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add("North",p1);
panel.add("South",scrollpanel);
frame.getContentPane().add(panel);
frame.setVisible(true);
frame.setSize(500,500);
catch(Exception e)
System.out.println(e);
ComboListener combolisten = new ComboListener();
combo.addActionListener(combolisten);
public static void main(String args[])
new Dynamictable();
class ComboListener implements ActionListener
public void actionPerformed(ActionEvent evt)
String collectvalue= combo.getSelectedItem().toString();
String qry = "Select * from Firstsemester where Matric_Number = ";
String test = null;
if(collectvalue.equals("All"))
query = "Select * from Firstsemester;";
else
Myquery dt = new Myquery();
test = "'"+dt.sendQuery(combo)+"'";
qry+=test;
//query.contains(null);
query.contains(qry);
query.equals(qry);
System.out.print(query);
System.out.println(query);
class Combodata
public Vector setdata()
String data = null;
Vector elem = new Vector();
try{
//adding the connection into the datasource
String url = "jdbc:odbc:mydata";
Connection con = DriverManager.getConnection(url);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement stat = con.createStatement();
ResultSet result = stat.executeQuery("select Matric_Number from Firstsemester;");
while(result.next())
data = result.getString("Matric_Number");
elem.add(data);
catch(Exception e)
System.err.println(e);
return elem;
class Myquery
JComboBox com;
public String sendQuery(JComboBox combo)
com = combo;
String collect = combo.getSelectedItem().toString();
return collect;

1. If you post GUI questions to this forum then you are using the wrong forum.
2. If you JDBC code is in the same class as GUI code then you ware coding it wrong.

Similar Messages

  • TS1292 Purchased gift cards about a year ago. Misplaced two of them. Found them yesterday, tried to use one today. Invalid. If the money is tagged to the card code why is it invalid? Now have to take photos of both sides and find receipt? Guess out $20?

    Purchased gift cards about a year ago. Misplaced two of them, but Found them yesterday. i tried to use one today. Invalid. If the money is tagged to the card code why is it invalid? Now have to take photos of both sides and find receipt? Finding the receipt might take as long as .finding the cards. If I paid hard earned money for the card from a computer company why would that card not be in their data base waiting to be activated? I guess I am out $20 to Apple for not activating immediately! My account was hacked once so I won't put a credit card in and live with gift cards. Now I am getting hit for $20, two gift cards for ten each. I now question who and how people are making money?? Is my only solution, buy card, redeem code instantly, purchase item?

    Hi Oxfordataloss,
    Thanks for posting. I'm really sorry you've had such problems with BT, it's certainly not the kind of service we would hope to provide. I'll take your comments on board and if you don't receive the final bill as expected please drop me an email with the account details and a link to this thread for reference.
    Cheers
    David
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)

  • When trying to use flash player it says to download the player. i have the latest player

    when trying to use flash player it says to download the player. i have the latest player

    I can assume that you're using IE11, and probably with Windows 8.1.
    This is a known problem with Internet Explorer 11, which Microsoft has been aware of since October 18 when they released their latest "untested" browser. The pages can't recognize the browser, so they don't recognize any of the plugins, like Flash Player. So far, Microsoft has made NO indication that they have any plan to fix it soon.
    Microsoft's recommendation is to use Compatibility View for affected pages, and "pretend" you're using an different browser. Trouble with that is it has seen limited success at best, and you have to individually enable it for EVERY page that has problems.
    I'm not big on "pretending" so I recommend actually using another browser.
    Firefox (from Mozilla)
    Opera (from Opera)
    Safari (from Apple)
    Chrome (from Google)
    ANY of those will work where IE11 won't, with the Flash Player Plug-in (For all other browsers), and Chrome doesn't even need that because it has its own Flash Player plugin built in.

  • SELECT * cannot be used in an INSERT INTO query when the source or destination table contains a multivalued field

    Hi,
    I am using Access 2013 and I have the following VBA code, 
    strSQL = "INSERT INTO Master SELECT * from Master WHERE ID = 1"
     DoCmd.RunSQL (strSQL)
    when the SQL statement is run, I got this error.
    SELECT * cannot be used in an INSERT INTO query when the source or destination table contains a multivalued field
    Any suggestion on how to get around this?
    Please advice and your help would be greatly appreciated!

    Rather than modelling the many-to-many relationship type by means of a multi-valued field, do so by the conventional means of modelling the relationship type by a table which resolves it into two one-to-many relationship types.  You give no indication
    of what is being modelled here, so let's assume a generic model where there is a many-to-many relationship type between Masters and Slaves, for which you'd have the following tables:
    Masters
    ....MasterID  (PK)
    ....Master
    Slaves
    ....SlaveID  (PK)
    ....Slave
    and to model the relationship type:
    SlaveMastership
    ....SlaveID  (FK)
    ....MasterID  (FK)
    The primary key of the last is a composite one of the two foreign keys SlaveID and MasterID.
    You appear to be trying to insert duplicates of a subset of rows from the same table.  With the above structure, to do this you would firstly have to insert rows into the referenced table Masters for all columns bar the key, which, presuming this to be
    an autonumber column, would be assigned new values automatically.  To map these new rows to the same rows in Slaves as the original subset you would then need to insert rows into SlaveMastership with the same SlaveID values as those in Slaves referenced
    by those rows in Slavemastership which referenced the keys of the original subset of rows from Masters, and the MasterID values of the rows inserted in the first insert operation.  This would require joins to be made between the original and the new subsets
    of rows in two instances of Masters on other columns which constitute a candidate key of Masters, so that the rows from SlaveMastership can be identified.
    You'll find examples of these sort of insert operations in DecomposerDemo.zip in my public databases folder at:
    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.
    In this little demo file non-normalized data from Excel is decomposed into a set of normalized tables.  Unlike your situation this does not involve duplication of rows into the same table, but the methodology for the insertion of rows into a table which
    models a many-to-many relationship type is broadly the same.
    The fact that you have this requirement to duplicate a subset of rows into the same table, however, does make me wonder about the validity of the underlying logical model.  I think it would help us if you could describe in detail just what in real world
    terms is being modelled by this table, and the purpose of the insert operation which you are attempting.
    Ken Sheridan, Stafford, England

  • HT1222 I am having issues with my iphone 4- it keeps locking up and giving me a black screen when i am trying to use it.  i took it to the at&t store where they told me i needed to update it.  I have the version 4.3.3 and i am unable to do anything else,h

    I have an iphone 4g and i am having problems with it locking up at times.  It will lock up and give me a blank screen.  When I took it to my local AT&T store they advised me to update it.  I am using the version 4.3.3 and I have tried to sync to Itunes, but have been unsuccessful.  I have not been able to update it at all.  When I plug in my phone to the computer, it will not sync at all.  Any suggestions?

        Oh boy! Acting kind of weird seems to be an understatement, aquaequus!
    What type of troubleshooting were we able to do with you? I want to make sure that we can get some sort of resolution for this problem.
    It is quite possible the battery door may get your phone in working order again. I'm not sure if the store has it in stock, but it is available in our warehouse for $14.99 which can be ordered via customer service.
    Tamara H.
    Follow us on Twitter @VZWSupport

  • Messages beta, does not connect to Internet when trying to use uninstall, but I clearly am on the internet, any ideas?

    I downloaded messages beta, and after trying video chat with my wife who was using iChat, I decided to uninstall, and every time I try to uninstall, I get a network problem saying that the messages beta uninstalled can't be downloaded as my computer isn't connected to the Internet, and I clearly am connected thru my wifi, any ideas how to get around this?

    Hi,
    Any version of iChat or the Message beta will have issues if you have two connections to the internet.
    In fact iChat 4 in Leopard has the worst issues particularly if the computer you are on is Sharing the Internet with other devices  (See System Preferences > Sharing > Internet Sharing)
    iChat can just about manage in Text Chats  to connect with other people.
    In Video Chats and Audio Only chats and Screen Sharing ichat needs to be in "One Place"
    With two IPs issued from a router for Wifi and Ethernet (See the differences in System Preferences > Network for Ethernet and Advanced Button > TCP tab for Wifi) means that iChat looks like it is in two places.
    It is worse if you share the Wifi of a neighbour and use Ethernet yourself.
    Using Ethernet may get your computer to access the DNS servers from your router more consistently so that Messages can find the place to download iChat 6  (There is evidence that both downloading Messages Beta and registering the Apple ID needs the correct or adequate DNS server info to work properly)
    This address for the Message Beta download seems to hard to find for some DNS servers
    http://swdlp.apple.com/cgi-bin/WebObjects/SoftwareDownloadApp.woa/wo/XeLd6tIQQ2O yGCki8irQgw/2.5
    (This is the accompanying "Thank you for Downloading" page)
    The point you make though, that a Ethernet connection may work better, is valid.
    8:32 PM      Sunday; May 13, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Lion 10.7.3)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Trying to use new YahooMail interface, I've got the message: Sorry, Mozilla Firefox optimized for Yahoo! is not available for your system.

    My hardware is moch more advanced than demanded for version of Firefox? optimized for Yahoo.
    Thank you for your help!

    Download latest Firefox 6.0.1 version from one of these links:
    * http://www.mozilla.com/en-US/firefox/new/
    * http://www.mozilla.com/en-US/firefox/central/
    * http://www.mozilla.com/en-US/firefox/fx/
    * http://www.mozilla.com/en-US/firefox/all.html
    Uninstall your current Firefox
    * https://support.mozilla.com/en-US/kb/Uninstalling%20Firefox
    * DO NOT SELECT TO REMOVE USER DATA AND SETTINGS
    Install Firefox using the downloaded installer file
    * https://support.mozilla.com/en-US/kb/Installing%20Firefox%20on%20Windows
    Check and tell if its working.

  • Trying to use GREP to add 2 spaces to the beginning of a line, under a particular circumstance.

    Hello,
    I am trying to add 2 blank spaces to the beginning of any line that has a punctuation at the end of that line, followed by a forced line break.
    I can get the GREP to find the punctuation at the end of a line with a forced line break:
    [[:punct:]](?=\r)
    But, is there a way to tell it to now add 2 spaces to the beginning of that line?
    Any guidence is greatly appreciated.
    thanks
    babs

    If applying a paragraph style works (nice thought!), then finding [[:punct:]]\n and applying the style works fine, no need for the grouping and the lookbehind. But if it's really the case that two spaces need to be inserted, then that's possible only if the text is not formatted at all. Then
    find ^.+[[:punct:]]\n
    change to \x20\x20$0
    will do the trick (\x20 is the space character). If the text does have any formatting, a script is needed.
    Peter

  • Trying to use airplay mirroring on ipad air.  The airplay switch does not show in control panel, only airdrop.  How do i get airdrop out of the way to find airplay switch?

    NO airplay switch in control panel, only air drop.  How do I find airplay switch?

    Unplug the Apple TV then plug it back in, do the same for your router, then reset your iPad by holding down the home and sleep buttons, waiting for the Apple logo, then let go of the buttons.

  • SSRS 2008, can I use exec sp and Select combo in dataset query pane for DataSet

    Hi, I'm trying to use this combo for my dataset: i.e. call sp and then use table resulting from this sp, and it give me an error
    <procedure or function has too many arguments specified> while generating report on Preview, but runs OK from query designer, I'm totaly lost.
    Can it be done??
    create table #temp (c1....c2)
    insert #temp
    exec sp_1000_Get_Mir
    select c1, c2 from #temp

    You need to use it like below if you want to select subset of columns from sp output
    http://beyondrelational.com/modules/2/blogs/70/posts/10812/select-columns-from-exec-procedurename-is-this-possible.aspx
    But I would still recommend using a wrapper procedure inside it create a temp table with structure some as your sp output and then select required columns from it
    ie like below
    CREATE PROC WrapperProc
    AS
    create table #temp (c1....c2)
    insert #temp
    exec sp_1000_Get_Mir
    select c1, c2 from #temp
    go
    Then call the WrapperProc from your report
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • BI publisher concurrent comes back with warning trying to use PL/SQL

    Hello,
    I am new to BI publisher and I am trying to use PL/SQL to generate XML and have the Publisher display the report with a template I have created. The concurrent is completing with a warning and from looking at the other forum posts I found the following in the OPP error logs...
    Template code:XML_TEST
    Template app: XML
    Language: en
    Territory: 00
    Output type: RTF
    [3/2/11 2:27:37 PM] [393078:RT2163613] Output file was found but is zero sized - Deleted
    [3/2/11 2:27:37 PM] [UNEXPECTED] [393078:RT2163613] java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at oracle.apps.xdo.common.xml.XSLT10gR1.invokeNewXSLStylesheet(XSLT10gR1.java:611)
    at oracle.apps.xdo.common.xml.XSLT10gR1.transform(XSLT10gR1.java:239)
    at oracle.apps.xdo.common.xml.XSLTWrapper.transform(XSLTWrapper.java:182)
    at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:1044)
    at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:997)
    at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:212)
    at oracle.apps.xdo.template.FOProcessor.createFO(FOProcessor.java:1665)
    at oracle.apps.xdo.template.FOProcessor.generate(FOProcessor.java:975)
    at oracle.apps.xdo.oa.schema.server.TemplateHelper.runProcessTemplate(TemplateHelper.java:5936)
    at oracle.apps.xdo.oa.schema.server.TemplateHelper.processTemplate(TemplateHelper.java:3459)
    at oracle.apps.xdo.oa.schema.server.TemplateHelper.processTemplate(TemplateHelper.java:3548)
    at oracle.apps.fnd.cp.opp.XMLPublisherProcessor.process(XMLPublisherProcessor.java:302)
    at oracle.apps.fnd.cp.opp.OPPRequestThread.run(OPPRequestThread.java:176)
    Caused by: oracle.xdo.parser.v2.XPathException: Namespace prefix 'ref' used but not declared.
    at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:806)
    at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:571)
    ... 17 more
    I am pretty sire the PL/SQL is OK beacuse if I run without a template the XML output is displayed as expected.
    Would anyone have any ideas on this?

    Here's your problem:
    "Caused by: oracle.xdo.parser.v2.XPathException: Namespace prefix 'ref' used but not declared.
    at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:806)
    at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:571)
    What version of BIP Desktop are you using? From the error message it appears to be Template builder for Word 11.1.1.3. eBS is probably using 5.6.3 .
    Try this - edit the fields in the template using MS Word. Under Help or Status, remove tags that contain <?ref.....?>. Save and upload the template.
    Hope this helps. If this works, please don't forget to give me points for the right answer.

  • HT1926 "the feature you are trying to use is  on  a network resource" message error when installing itunes

    "the feature you are trying to use is  on  a network resource"  is the message error I received when installing itunes.  I downloaded the file and saved it.  The same thing happended when I simply ran it as well.

    Hello, uclan1.
    This article will help you with the error that you are receiving. 
    "The feature you are trying to use is on a network resource that is unavailable" alert when removing Apple software in Windows
    http://support.apple.com/kb/TS3704
    Cheers,
    Jason H. 

  • TS1398 I'm trying to use the us netflix and I not sure what Dns I should use or if I need a VPN

    I'm trying to use us netflix it was working but the dns is not working and I don't understand what a VPN is

    There is no particular reason yo should have to adjust DNS settings or use VPN to connect to Netflix, unless you are doing so from a county where it is not legally available.

  • When trying to use photo as wallpaper, cannot scale the image to size I want.  This feature worked fine with ios6

    When trying to use a photo for wallpaper, cannot scale the image to size I want to use.  Feature worked fine in iOS6

    James, thank you. I'm experiencing the same issue and submitted feelback at that link. I'm trying to use the same pumpkin image I used last year for Halloween on my lock screen and attempting to follow instructions (Move and Scale) and would like to make the image smaller so that it appears BELOW the time and date, but although I'm able to move the image, I'm unable to scale it - make it smaller. I've since tried this with several other photos with the same outcome. It seems that in iOS 7 one can make images bigger, but not smaller. I'm not sure what the logic behind that could be.

  • Trying to use old iPod as backup volume but it isn't recognized.

    Hello.
    I am trying to use a 20GB iPod (generation 1) as the backup volume for Time Machine. I assume that I can designate which parts of my system for Time Machine to backup, such that the size of the iPod in relation to the size of my hard drive wouldn't matter.
    I have enabled disk use on the iPod and stripped all the old files from it, but it does not appear in the Time Machine list.
    Any help on how I can fix this? Perhaps a formatting issue?
    Thanks.

    "Just keep in mind that it may void warranties."
    Meaning for the iPod? I've had it for five years. I'm pretty sure it is worthless and uncovered by any warranty.
    On the other hand, if you mean it might damage my computer somehow and void its coverage in the process, I will reconsider this option.
    Thanks so much for your help.

Maybe you are looking for

  • Mac Mini (2012) as Wireless Gateway

    I want to turn my mac mini into a wireless gateway. I  have "pf" I need to know how to turn on wireless ap mode on? What command line tools are available? OpenBSD has "hostapd" for this. I plan to have my mini serve as my gateway router as well as me

  • Authorization check in tocde CJ20N for WBS elements

    Hi Experts, in cj20n tocde, if we give authorization to wbs element then networks and activities attached to this wbs element are authorized for edit,create..This is my requirement. I used 3 function modules EXIT_SAPLCNAU_002, EXIT_SAPLCNAU_003, EXIT

  • Digital camera not recognised on iMac

    Hi Yesterday I connected my canon digital ixus camera to my iMac and copied over some photos, via usb, no problem. Today I am trying to do exactly the same but the camera is not seen at all. Nothing has changed, and I have used the same procedure as

  • Brand new MacBook Pro can't handle 720p Video in iMovie?

    Well, my Black 2.0 GHz Core Duo MacBook has been replaced by the new 13" 2.26 Core 2 Duo MacBook Pro (I had to pay the difference) and I had it upgraded to 4GB of Ram and a 320GB Hard Drive! I use a Kodak z1085 IS Digital Camera that records videos i

  • All my photos sync in landscape mode (even portrait ones) from my Mac IOS 7 on my new iPad Aid. How can I fix this?

    WHen i sync my new iPad Air IOS 7 , all my photos sync in landscape mode.  How can I keep the original orientation of photos? If I edit and rotate, it is saved in camera roll, not in the album.