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 8697131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:26:36+00:00 2026-06-13T01:26:36+00:00

I need to check if a table with a specific tablename exists in a

  • 0

I need to check if a table with a specific “tablename” exists in a database from my java program.

The database may be of different type, viz. MS SQL Server, Oracle, DB2. I have a connection object to the database. Is there a single method that can work for all the types of databases?
I might have to extend the java program to support more db Types, thus a single approach for all DB types would be very much helpful.

The code that I am using. This appears to work correctly against a SQL Server database but does not find the table in Oracle or DB2

DatabaseMetaData meta = conn.getMetaData(); 
ResultSet res = meta.getTables(null, null, "TABLE_NAME", null); 
if(!res.next()){ 
  //table does not exist. 
} else{
   //table exists. 
}
  • 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-06-13T01:26:37+00:00Added an answer on June 13, 2026 at 1:26 am

    Very simplistic:

    SELECT
        1
    FROM
        TABLE
    ;
    

    If it throws an exception the table does not exist (or something else is wrong).
    Otherwise:

    http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getTables(java.lang.String, java.lang.String, java.lang.String, java.lang.String[])

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

Sidebar

Related Questions

i need to check for a specific DateTime value in my table from my
I need to check If a column value (string) in SQL server table starts
I need to write q query where I check if the table exists, and
I use MS SQL 2008 R2, I need create a Table with a CHECK
I need to check if this index not exist in specific table name not
I have a scenario where I need to check for 10,000 different specific names
All, I need to write a data set from a large SQL table to
Before inserting data into table i need to check against duplicate records and report
I need to check if a database is totally empty (no tables) using an
I need to check for duplicates before saving to the database in the create

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.