Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:47:24+00:00 2026-05-25T01:47:24+00:00

Imagine I have a query like SELECT * from table1 a, table2 b where

  • 0

Imagine I have a query like

SELECT * from table1 a, table2 b where (WHATEVER)

Maybe both tables have the same column name. So I though it would be nice to access the data via

resultSet.getString("a.columnName");
resultSet.getString("b.columnName");

But this backfires on me and I get nothing. I read the API, but they don’t really talk about this case. Is such a feature vendor dependent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:47:24+00:00Added an answer on May 25, 2026 at 1:47 am

    JDBC will simply name the columns by what is specified in the query – it doesn’t know about table names etc.

    You have two options:

    Option 1: Name the columns differently in the query, ie

    SELECT
        a.columnName as columnNameA,
        b.columnName as columnNameB,
        ...
    from table1 a, table2 b where (WHATEVER)
    

    then in your java code refer to the column aliases:

    resultSet.getString("columnNameA");
    resultSet.getString("columnNameB");
    

    Option 2: Refer to the column position in your call to the JDBC API:

    resultSet.getString(1);
    resultSet.getString(2);
    

    Note that the JDBC API uses one-based indexes – ie they count from 1 (not from 0 like java indexes), so use 1 for the first column, 2 for the second column, etc

    I would recommend option 1, because it’s safer to refer to named columns: Someone may change the order of the columns in the query and it would silently break your code (you would be accessing the wrong column but would not know), but if they change the columns names, you’ll at least get a “no such column” exception at runtime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have two tables in a DB like so: products: product_id name ----------------
I have several hosts from which i want to do the same query. So
I have this postgres sql query: select * from stats where athlete_id = 5
Imagine I have these python lists: keys = ['name', 'age'] values = ['Monty', 42,
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a query that can be summarised in SQL as follows; Select S.StockCode
Imagine you have those 3 tables: And imagine there is massive data according to
If i have tables such as: table_1: 1, 'Hello My Name is Hal', '2009:11:02
I have a query that pulls up questions from one table and answers from
I have SQL data that looks like this: events id name capacity 1 Cooking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.