Coul anyone help me with a sql query that involves a jcombobox?

HI all
i'm writing this program in wich i want to query a table in a ms access db. My os is win2000 and i use access2000.
so i have a list of categories in a jcombobox.When one of the categories is selected i have to display the corresponding product for that category in a jtext area.
I wrote the code.But i keep getting an erro at run time when i selct an item from the combobox wich is :
SQL Error: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid descriptor index 20 S1002
here's my code:
boxcategories.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String mySelection = (String)cb.getSelectedItem();
//connecting to the data base
Connection connec;
String data = "jdbc:odbc:MyDB";
try {  
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connec = DriverManager.getConnection(
data , "", "");
PreparedStatement ps = connec.prepareStatement(" SELECT Category from products"+
" WHERE Category =?");
ps.setString(1,mySelection );
ResultSet rs = ps.executeQuery();
if (rs.next() )      {
products.append(rs.getString(1)+"\t"+
rs.getString(2)+"\t\t"+
"$" rs.getString(4) "\t ");
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception x) {
System.out.println("Error: " + x.toString()
+ x.getMessage());
so what do u think i should do
Franck

hi
i'm having a problem with this query.When i select a categoryfrom
the combobox,i only get one corresponding product displayed in the jtextarea
I tryed everythin but i cant get this code to work correctly.
i want that when i select a category from the combobox that the corresponding product of wich the in stock quantity is >20 to be displayed
in one jtext area and thos who's in stock quantity is < in another jtext area
What should i do?
here's my code
boxcategories.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String mySelection = (String)cb.getSelectedItem();
//connecting to the data base
Connection connec;
String data = "jdbc:odbc:MyDB";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connec = DriverManager.getConnection(
data , "", "");
PreparedStatement ps = connec.prepareStatement(" SELECT Category from products"+
" WHERE Category =?");
ps.setString(1,mySelection );
ResultSet rs = ps.executeQuery();
if (rs.next() ) {
products.setText((rs.getInt(1)+"\t"+
rs.getString(2)+"\t\t"+
"$" rs.getFloat(4) "\t " rs.getInt(5) "\n" );
if(rs.getInt(5) < 20)
products1.setText(rs.getInt(1)+"\t"+
     rs.getString(2)+"\t\t"+
     "$" rs.getFloat(4) "\t " + rs.getInt(5) +"\n" );
else
produitdescription.setText("");produitdescription1.setText("");
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception x) {
System.out.println("Error: " + x.toString()
+ x.getMessage());
when i selct a category i get this runtime error at the same time the product is displayed
SQL Error: java.sql.SQLException: No data found 0 null
what should i do
FRanck

Similar Messages

  • Can anyone help me with a repeating pattern that is staggered?

    Can anyone help me with a repeating pattern that is staggered and must be aligned perfectly while staggered. Is there a way to do this? I keep staggering it by eyeball and need it to be accurate and each row is offset.
    My art board is 19.25x11.50 I have a repeating logo and name underneath (hard to see) I am setting this up for a print design to go onto tissue paper for insert into a shoe box. Any help is greatly appreciated?
    Thanks,

    Option drag your object horizontally to make a copy or use Move and copy if you need a precise increment. The hit Cmd+D a few times to make duplicates with the same spacing.
    Hit Enter again and make a note of the increment on a piece of paper. Cancel.
    Select everything and use the same increment, now in a vertical direction, to make 2 further copies.
    Take the middle row and move it horizontally by half of the increment. This means that the circles in the middle row are positioned horizontally half way between those in the other two rows.
    Draw your defining rectangle so that its corners are on the centres of those 4 circles. (This gives you its right size but you may possibly need to move it a bit.) Send it to the back of your stack.
    Drag those 8 circles and the rectangle to your Swatches panel.
    (If you’re on Windows read Ctrl instead of Cmd and Alt instead of Option.)

  • Please help me with this SQL query

    I am practicing SQL queries and have come across one involving fetching data from 3 different tables.
    The three tables are as below
    <pre>
    Country
    location_id          country
    loc1          Spain
    loc2          England
    loc3          Spain
    loc4          USA
    loc5          Italy
    loc6          USA
    loc7          USA
    </pre>
    <pre>
    User
    user_id location_id
    u1 loc1
    u2 loc1
    u3 loc2
    u4 loc2
    u5 loc1
    u6 loc3
    </pre>
    <pre>
    Post
    post_id user_id
    p1 u1
    p2 u1
    p3 u2
    p4 u3
    p5 u1
    p6 u2
    </pre>
    I am trying to write an SQL query - for each country of users, display the average number of posts
    I understand the logic behind this that we first need to group together all the locations and then the users belonging to one country and then find the average of their posts.
    But, i'm having a difficulty in putting this in SQL form. Could someone please help me with this query.
    Thanks.

    select
    country.country,
    count(*) Totalpostspercountry,
    count(distinct post.user_id) Totaldistincuserspercountry,
    count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
    from
    country, muser, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    group by country.country
    The output is like this for your sample data - hope this is what you were looking for :)
    COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
    England,1,1,1,
    Spain,5,2,2.5,

  • HT5622 Please an you help me with an identity query that I have using your 'rescue' services for an iPad?

    I have just helped set up an iPad for my elderly cousin who is in her mid 80s.  She cannot cope with multipile log in and passwords, so to help her out in case she loses her information, I have given my e-mail address for use as 'rescue' in case her information goes astray.  I have just had an e-mail in from you a couple of days ago asking me to verify if I had set up the 'rescue' services for myself etc.  The answer is no, but I would like to be able to use my address for my cousin's information - how can I make this work please?

    For info we are fellow users here on theseforums, you're not talking to iTunes Support nor Apple.
    The email should have a 'verify now' link in it e.g.
    If you click on that 'verify' link you should be taken to a browser and be prompted to sign into your cousin's account, abd doing that will verify the address as the rescue email address on your cousin's account. As it's only a rescue email address you don't have to use the verify link and verify it, it should still work as a rescue email address on her account (though you should probably verify it).

  • Can anyone help out with an I issue that is showing on my iPhone?

    Recently I discovered I was running version6.13 (10B329)
    Can anyone explain what this is and how it ended up on my iPhone?

    That simply indicates the build number (sub-version, sort of) of the software, and takes into account beta and test builds. From a user standpoint, it doesn't mean a great deal. There would have been only one "build" available for your device.

  • I need to reinstall my operating system for 10.5 after seeing a file folder and question mark flashing on my start up screen. Can anyone help me with this?

    I need to reinstall my operating system for 10.5 after seeing a file folder and question mark flashing on my start up screen. Can anyone help me with this?

    Hello,
    That means it can find the Hard Drive, or can't find the things needed for booting.
    See if DU even sees it.
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Can anyone help me with Query ?

    Hi Experts,
    Can anyone help me with Query? the query need to retrieve below info based on set of books ID.
    Needed columns:
    1 SOB     
    2 Legal Entities      
    3 Fixed Asset Org Name     
    4 Applications/Responsibilities     
    5 Operating Units     
    6 Inventory Org     
    7 COA     
    8 Assigned Responsibilities
    Thanks

    Duplicate post -- Can you help on below Query ?
    Please post only once!

  • Help with translating SQL query from SQL Server syntax to Oracle syntax

    Hi,
    is it someone that can help me translate following SQL query from SQL Server syntax to Oracle syntax.
    SELECT ID,
    [LMT(MTR)] = MAX(case when TYPE = 'LMT' then VALUE end),
    [AAD(KGM)] = MAX(case when TYPE = 'AAD' then VALUE end),
    [VOL(MTQ)] = MAX(case when TYPE = 'VOL' then VALUE end)
    FROM yourtable
    GROUP BY ID
    Your help is highly appreciated, thanks in advance.

    Like this,
    SELECT ID,
    MAX(case when TYPE = 'LMT' then VALUE end) LMT_MTR,
    MAX(case when TYPE = 'AAD' then VALUE end) AAD_KGM ,
    MAX(case when TYPE = 'VOL' then VALUE end) VOL_MTQ
    FROM yourtable
    GROUP BY ID-Arun

  • Selection screen - search help with dynamic sql query

    hey ,
    is it possible to change the search help of the selection field ?
    when i create the range table i put a data element :
    create a range table that consists of this new data element
      LT_RANGE_TABLE = WD_THIS->M_HANDLER->CREATE_RANGE_TABLE( I_TYPENAME = 'S_CARR_ID' ).
    can i control the search help via the the data element or by other methods ?
    i want that when the user press F4 the values that will show is the result of a sql query that i will write .
    is it possible ?
    thanks
    ASA.

    Hi,
    yes it is possible...
    This is my test code for say personal number select options...
    lt_range_table = wd_this->m_handler->create_range_table(
      i_typename = 'PERSNO' ).
    add a new field to the selection
      wd_this->m_handler->add_selection_field(
      i_id = 'PERSNO'
    I_VALUE_HELP_TYPE = if_wd_value_help_handler=>CO_PREFIX_SEARCHHELP
    I_VALUE_HELP_ID = 'ZHELP_WDA_PERNR'   "this is the custom search help we need to create
    I_NO_INTERVALS = abap_true
      it_result = lt_range_table
      i_read_only = read_only ).
    do the following:
    1) copy the std function module: F4IF_SHLP_EXIT....to ZF4IF_SHLP_EXIT_pernr (in my case i am testing for pernr so my fm
    name is like that....obviously it can be anything you want...under the recommended naming convention)
    2) look for "STEP SELECT"
    STEP SELECT    (Select values)
    3)write the code as follows:
    "NOTE: this is my testing code...but you can build your logic on it....
    IF CALLCONTROL-STEP = 'SELECT'.
    types: begin of zpri_listing,
    pernr type PERSNO,
    end of zfund_listing.
    DATA: lo_syuname TYPE sy-uname.
    data itab type standard table of Zpri_LISTING.
    data wa type zpri_listing.
        DATA : t_fields LIKE TABLE OF shlp_tab-fielddescr.
        DATA : w_fields LIKE LINE OF shlp_tab-fielddescr.
        DATA : l_fname TYPE dfies-lfieldname.
        IF lo_syuname <> sy-uname.  "means we were here before and ITAB is filled...fm retains its data values...unless refresh happens
    "this if condition make sure that we do not do this select all the time as long as the same user is logged in...
    "a user can press f4 many times...you might want to enhance this logic a little bit more for performance
          lo_syuname = sy-uname.
    ))))))))))))))HERE DO YOUR SELECT(((((((((((((((((((((
    select pernr from "sometable" into table itab.
        ENDIF.
        LOOP AT shlp_tab.
          LOOP AT shlp_tab-fielddescr INTO w_fields.
            l_fname = w_fields-fieldname.
            CALL FUNCTION 'F4UT_PARAMETER_RESULTS_PUT'
              EXPORTING
                parameter               = w_fields-fieldname
              OFF_SOURCE              = 0
              LEN_SOURCE              = 0
              VALUE                   =
               fieldname               = l_fname
              TABLES
                shlp_tab                = shlp_tab
                record_tab              = record_tab
                source_tab              =  itab
              CHANGING
                shlp                    = shlp
                callcontrol             = callcontrol
             EXCEPTIONS
               parameter_unknown       = 1
               OTHERS                  = 2
          ENDLOOP.
        ENDLOOP.
        IF sy-subrc EQ 0.
          callcontrol-step = 'DISP'.
        ELSE.
          callcontrol-step = 'EXIT'.
        ENDIF.
        EXIT. "Don't process STEP DISP additionally in this call.
      ENDIF.
    4) save and activate this function module...
    5) go to se11 and create "Elementary srch hlp"....
    6) fill out all the necessary fields...i am assuming that you already know how to create the search helps...
    look for this field: "Search help exit" and put your function name which you created in the above steps...
    in this example i have: ZF4IF_SHLP_EXIT_pernr....
    7) create and activate the search help....
    hope this helps...i just tested this and it is working for me....
    Thanks..
    AS...

  • Help needed in framing SQL query.

    Hi,
    I have table having following schema:
    PRODUCT_ID         INT
    DATE                   DATETIME
    ITEMS_SOLD         INT
    This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
    Any help to get the SQL query will be appreciated.
    Thanks,
    Akshay.

    PRODUCT_ID      DATE           ITEMS_SOLD
    1          10/10/2011     3
    1          11/10/2011     3
    1          12/10/2011     3
    1          13/10/2011     3
    1           16/10/2011     5
    2          10/10/2011     4
    2           11/10/2011     4
    2          12/10/2011     4
    2          13/10/2011     4
    2           14/10/2011     4
    2          15/10/2011     4
    2          16/10/2011     4
    Output:
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3                4     
    2          4               7
    Explanation of results:
    The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3               4     
    as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
    For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    2           4               7
    Other case where same PRODUCT_ID have different units sold on each day should be ignored.
    I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
    -Akshay.

  • Help me write a SQL query; urgent

    Hi, can somebody please help me write a SQL query.
    I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
    I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
    Does anybody help me please ?
    thanks alot.

    Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
    I'm not sure exactly what you want.
    Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
    If so, it would be like this, I think: insert into t4
    select t1.c1
    , t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
    from t1, t2, t3
    where t2.c1 = t1.c1
    and t3.c1 = t1.c1If that's not what you want, please clarify.
    And next time maybe you should post your SQL question in a SQL forum.

  • OTL I am trying to wright a SQL query that will return the date the timesheet was submitted and date/time it was approved, can anyone guide me on this?

    Hi
    I am trying to wright a SQL query that will return the date the timesheet was submitted and date/time it was approved, can anyone guide me on this?
    I basically need person name who submitted, date - time it was submitted for approval, then the person who approved it and the date - time that it was approved
    Thanks
    Ruby

    Ruby,
    you can start with HXC_TIMECARD_SUMMARY table for submitter detail. But for approver details, i think you need WF tables to get the data for item type HXCEMP.

  • Can anyone help me with Magicjack? after I purchased US number I am unable to log in on my Iphone, I keep getting an error "YOUR DEVICE IS NOT ON THIS ACCOUNT" I contacted MJ support but they are very much useless and dont know how to fix it!

    can anyone help me with Magicjack? after I purchased US number I am unable to log in on my Iphone, I keep getting an error "YOUR DEVICE IS NOT ON THIS ACCOUNT" I contacted MJ support but they are very much useless and dont know how to fix it!

    There's a whole lot to read in your post, and frankly I have not read it all.
    Having said that, this troubleshooting guide should help:
    http://support.apple.com/kb/TS1538
    In particular, pay attention to the mobile device support sections near the bottom, assuming you have already done the items above it.

  • Can anyone help me with a problem i am having with my music on my iPhone 4S. I have put alot of Compilation CDs in my library on iTunes. I download these tracks onto my phone, everything is ok so far. Now, this is what is niggling me and I don.t know how

    Can anyone help me with a problem i am having with my music on my iPhone 4S. I have put alot of Compilation CDs in my library on iTunes. I download these tracks onto my phone, everything is ok so far. Now, this is what is niggling me and I don.t know how to resolve it. This is my problem: 
    Have downloaded for example: Queen – Bohemium Rhapsody from a compilation album as well as a few complete Queen Album CDs into the iTunes library and then put them into playlists,
    When I go onto my phone and select Queen on the MUSIC app using Songs tab at the bottom of the screen it will display all Queen songs and their resective Alum pics, that is all those not in a complilation album, .
    If I know the song title I can select the songs tab and find the song that way,
    I’ve tried fiddling with the settings in the iTunes app by going to ‘get info’ tab and trying to sort the problem out that way but am not having much luck.What I want the phone to do is show, for example all Queens songs including those in compilation albums. Can this be done, would be grateful for any ideas on how it can be done, that is if ic can be done, any ideas
    Thanks for your help

    Try assigning Queen as the Album Artist on the compilations in iTunes on your computer.

Maybe you are looking for

  • New mac mini setup can't see Bluetooth keyboard

    Brand new mini and in setupmit can't see Bluetooth keyboard or trackpad. Any ideas on how to complete setup? Anyone else had this problem?

  • Sharepoint Report is taking very long time to load

    SharePoint(2010) Report is taking very long time to load and display in first attempt but from the next attempt it loads and display result normally. It's urgent..please help how to troubleshoot ...

  • Sample/bit rate for Garage Band '08

    Hello, I don't have a Mac yet, but am going to get the mini soon and do some acoustic/keyboard stuff in Garage Band to get back into recording. What is the sample and bit rate for the new version? I had read that older versions were 16? Thanks. Joe

  • No sound from jack

    I have a Mac Mini and the sound has stopped working via the external jack. The internal speaker still produces sound, which mutes when you plug in a jack but nothing comes out of the jack. It worked until quite recently. Is this definitely a hardware

  • Can't import raw images

    I want to import RAW images. Have always been able to import JPEG's to iPhoto. Reformatted memory card. Took picture. Picture appears visible on playback. When I import, iPhoto says the image is unreadable. What to do?