Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Posts
    2

    Unanswered: "Many to many" java and MS Access

    Hi! I have two tables, that I have connected via a third so that a "many to many" connection has been established. I made it in Java and a MS Access database.

    It looks like this:

    String query = "select K.* "+
    "from Student AS S, Kurs AS K, Godkaend AS G where K.Kid = G.Kid " +
    "AND S.Sid = G.Sid AND G.Moment = 'Tentamen' AND S.Sid ="+tal;

    String query2 = "select S.* "+
    "from Student AS S, Kurs AS K, Godkaend AS G where K.Kid = G.Kid " +
    "AND S.Sid = G.Sid AND G.Moment = 'Tentamen' AND K.Kid ="+tal;

    Where Student and Kurs ("course", I'm Swedish) is connected via the table Godkaend.

    This works fine. The problem is, that I want to be able to choose the kolumns I want. Something like this:

    String query = "select K.Kid, K.Namn "+
    "from Student AS S, Kurs AS K, Godkaend AS G where K.Kid = G.Kid " +
    "AND S.Sid = G.Sid AND G.Moment = 'Tentamen' AND S.Sid ="+tal;

    I think this should work, but perhaps theres a special way when you use MS Access.

    The printout of the query and the errormessage comes after my tables:

    Student contains:

    Sid (Primary key)
    Namn(name)

    Kurs contains:

    Kid (Primary key)
    Name
    Litteratur

    Godkaend contains:

    Sid (Secondary key)
    Kid (Secondary key)
    Moment (Like exams, reports and stuff)
    Datum (date)
    Resultat (relult)

    Printout and error-msg:

    select K.Kid from Student AS S, Kurs AS K, Godkaend AS G where K.Kid = G.Kid AND S.Sid = G.Sid AND G.Moment = 'Tentamen' AND S.Sid =1

    java.sql.SQLException: Column not found
    at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(JdbcOdb cResultSet.java:1852)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbc ResultSet.java:413)
    at Databashanterare.selectSomeFromExempel(Databashant erare.java:179)
    at HuvudFrame.actionPerformed(HuvudFrame.java:383)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1786)
    at javax.swing.AbstractButton$ForwardActionEvents.act ionPerformed(AbstractButton.java:1839)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:258)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:245)
    at java.awt.Component.processMouseEvent(Component.jav a:5100)
    at java.awt.Component.processEvent(Component.java:489 7)
    at java.awt.Container.processEvent(Container.java:156 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:3615)
    at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
    at java.awt.Component.dispatchEvent(Component.java:34 77)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:3483)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3198)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3128)
    at java.awt.Container.dispatchEventImpl(Container.jav a:1613)
    at java.awt.Window.dispatchEventImpl(Window.java:1606 )
    at java.awt.Component.dispatchEvent(Component.java:34 77)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 456)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:100)

  2. #2
    Join Date
    Jul 2004
    Posts
    2
    I've solve the problem.

    I had a query like:


    String query = "SELECT K.Kid, K.Namn "+
    "FROM Student AS S, Kurs AS K, Godkaend AS G where K.Kid = G.Kid " +
    "AND S.Sid = G.Sid AND G.Moment = 'Tentamen' AND S.Sid ="+tal;

    Then I tried to put all of the columns value into a vector, bur since I hadn't fetch the value for, like below, litteratur, I couldn't put it in a variable.

    I solved it by marking out "Litteratur". That is, the people at sun forum solved it for me.

    (tabell.equals("Kurs"))
    {
    Vector rowVector = new Vector();
    rowVector.add(new Integer(rs.getInt("Kid")));
    rowVector.add(rs.getString("Namn"));
    //rowVector.add(rs.getString("Litteratur"));
    dataVector.add(rowVector);
    }

Posting Permissions

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