Results 1 to 3 of 3
  1. #1
    Fleur is offline Member
    Join Date
    Apr 2008
    Posts
    19
    Rep Power
    0

    Default ms access jdbc query problem

    Dear Forum,
    I'm a complete java newby so please bear with me :/

    I'm trying some things out with java and ms access.
    I manage to connect to my db, and get data from a table. However I'm running into problems when I need data from 2 related tables.
    The following query works fine in access

    Java Code:
    select * from table1 t1, table2 t2
    i get a column not found error when trying to get the data in java using
    Java Code:
    table1id = rs.getInt("t1.Id");
    rs is a resultset from the executed query and works fine when i use
    Java Code:
    select * from table1
    I can't seem to find an example with google of a 2 table query

    Can anyone point me in the right direction?

    Cheers!

    f.

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Try to use rs.getMetaData() to see what are the column names. I don't think you will get the column names prefixed with table names. On the other hand "select *" is not such a good idea. It is way better to specify what columns you want exactly and in what order and to specify your own names in case of duplication.
    One thing I don't understand is the purpose of your query. I don't know Access but it looks like you are gonna get a cartesian product of all the rows in the two tables. Is this what you want?
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  3. #3
    Fleur is offline Member
    Join Date
    Apr 2008
    Posts
    19
    Rep Power
    0

    Default

    2WIMC: the error was in the following line:

    Quote Originally Posted by Fleur View Post
    Java Code:
    table1id = rs.getInt("t1.Id");
    The name of the column in the rs is "Id" and NOT "t1.Id"

Similar Threads

  1. Jdbc problem
    By abhiN in forum JDBC
    Replies: 1
    Last Post: 03-21-2008, 05:10 AM
  2. JDBC select problem
    By abhiN in forum JDBC
    Replies: 0
    Last Post: 03-12-2008, 08:09 AM
  3. Problem in Servlet with JDBC
    By *New Programer* in forum Java Servlet
    Replies: 2
    Last Post: 12-20-2007, 09:15 AM
  4. JDBC problem
    By Swamipsn in forum New To Java
    Replies: 1
    Last Post: 08-13-2007, 06:05 PM
  5. JDBC problem
    By peiceonly in forum Threads and Synchronization
    Replies: 2
    Last Post: 08-03-2007, 01:42 PM

Posting Permissions

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