Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Reply
 
Thread Tools
Old 08-12-09, 08:21 PM   #1
ivanyeates
Registered User
 
Join Date: Aug 2009
Posts: 1
Default JDBC / MS ACCESS Problem

Im getting an:

ERROR: findSuppliersCandy(): Column not found

error in my program.
i have two related tables. One supplier table and one candy table for different types of candy.
the method below is trying to retrieve all the candy entries related to a specific supplier by passing a supplier id as a parameter

below is the code - any help would be appreciated

thanks

Code:
public List<Candy> findSuppliersCandy(int supplierId) throws DaoException {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<Candy> candylist = new ArrayList<Candy>();
        try {
            con = getConnection();
            String query = "SELECT * FROM SUPPLIERS WHERE SUPPLIERID = ?";
            ps = con.prepareStatement(query);
            ps.setInt(1, supplierId);

            rs = ps.executeQuery();
            if (rs.next()) {
                supplierId = rs.getInt("SUPPLIERID");
                String name = rs.getString("NAME")

           query = "SELECT * FROM CANDY WHERE SUPPLIERID = ?";
                
                ps = con.prepareStatement(query);
                ps.setInt(1, supplierId);
                ResultSet rs2 = ps.executeQuery();
                if (rs2.next()) {

                    int candyId = rs.getInt("CANDYID");
                    String candyname = rs.getString("CANDYNAME");
                    String candyprice = rs.getString("CANDYPRICE");
                    
System.out.println(candyId + "\t" + candyname + "\t" + candyprice);
                    Candy candy = new Candy(candyId, candyname, candyprice);
                    candylist.add(candy);
                    rs2.close();
                    rs2 = null;
                }
            }
        } catch (SQLException e ) {
            throw new DaoException("findSuppliersCandy(): " + e.getMessage());
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (ps != null) {
                    ps.close();
                }
                if (con != null) {
                    freeConnection(con);
                }
            } catch (SQLException e) {
                throw new DaoException("findSuppliersCandy(): " + e.getMessage());
            }
        }
        return candylist;
    }
ivanyeates is offline   Reply With Quote
Old 08-15-09, 03:55 PM   #2
Zhivago
*BANNED*
 
Join Date: Jan 2008
Posts: 184
Default Re: JDBC / MS ACCESS Problem

Amazingly enough, it appears as if you are referencing a column that doesn't exist. I trust you understand what this means.

Check to make sure columns all columns you reference, such as 'CANDYID', 'CANDYPRICE', 'SUPPLIERID', etc.. all exist with no typos.
Zhivago is offline   Reply With Quote
Old 08-30-09, 04:29 PM   #3
jcrox
Mahna Mahna
 
jcrox's Avatar
 
Join Date: Jul 2006
Location: Madison, Wi
Posts: 6,134
Default Re: JDBC / MS ACCESS Problem

I don't really use MS Access but with MySQL the first thing I usually do is open up SQL Browser, copy and paste the SQL statement into it and run it to make sure that I'm getting back the data that I'm expecting as well as check the column names to make sure that I haven't screwed anything up there.

If I don't find my error there I'll usually add the following to my catch statement: System.out.println(e.printStackTrace);
and figure out which column it is that is not being found and investigate from there.
__________________

Gaming

MSI MPower Z87 | 4770k | CNPS9900MAX-B | 8GB G.Skill 1866 | EVGA GTX760 |ThermalTake 850w | X-Fi Titanium | HAF | Asus PA248Q | Lycosa | Death Adder | Win8 Pro 64

Dev/Backup

MSI GD65 | 2500k | H50 | 8GB G.skill | GTX570 | Ubuntu 13.10

Laptop

17" Inspiron | i5 | 4GB DDR3 | 500GB HDD | Win7 Pro 64

jcrox is offline   Reply With Quote
Old 09-15-09, 10:47 PM   #4
Tuork
Official pain in the ass
 
Tuork's Avatar
 
Join Date: May 2003
Location: 127.0.0.1
Posts: 1,197
Send a message via MSN to Tuork
Default Re: JDBC / MS ACCESS Problem

Quote:
Originally Posted by Zhivago View Post
Amazingly enough, it appears as if you are referencing a column that doesn't exist. I trust you understand what this means.

Check to make sure columns all columns you reference, such as 'CANDYID', 'CANDYPRICE', 'SUPPLIERID', etc.. all exist with no typos.
What he said.
__________________
My avatar: "An obscure and non sensical pattern made to get people to post what they think it is" - Vamp

Dimitri:
Dell XPS M1530
Core2Duo T5550 1.86Ghz | 3GB DDR2 | 8600M GT 256MB | 250GB Hdd | BenQ FP202W 20" LCD | MX1000 mouse | Inspire T5400 5.1
Tuork is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:14 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.