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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:54:48+00:00 2026-06-04T07:54:48+00:00

I usually use SELECT 1 as my preferred validation-query from tomcat jdbc pools, because

  • 0

I usually use SELECT 1 as my preferred validation-query from tomcat jdbc pools, because it returns only one row with the result 1 that is very faster, but today I’ve found one terrible mistake:

My database only has one table with its primary key and is not nullable. This table sometimes is dropped, and then appears again by application circumstances. And that’s the problem, SELECT 1 validate connection to database because it’s already up but the table is missing so I get a terrible exception.

So, the solutions passes by finding one validation-query against the only table that exists in the database. And also, I need the query to be as fast as possible, because the performance in the application is one of the main objetives.

You can answer than an obvius query may be SELECT 1 FROM THE_TABLE but this query returns 1 for each row that the table has, and that’s not very quick.

So, what could be the faster validation-query to this table??

EDIT

If I need to return at least one result, How should be the validation-query?
I ask this because some pool implementations, like commons-dbcp doesn’t accept a query without results as a validated query.

  • 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-04T07:54:50+00:00Added an answer on June 4, 2026 at 7:54 am

    How about this, which should validate the table exists without actually loading any data by pulling 0 rows and no actual columns.

    SELECT TOP 0 1 FROM THE_TABLE
    

    Demo: http://www.sqlfiddle.com/#!3/c670b/3


    There are also built-in ways to check for the existance of objects in SQL SERVER. Here are two examples that do effectively the same thing.

    select count(1) from information_schema.tables where table_name = 'THE_TABLE'
    select OBJECT_ID('THE_TABLE') is not null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Usually, I use SELECT * FROM tableName WHERE fieldName LIKE '%string%' to find every
In Oracle, usually query like this for paging. SELECT * FROM (SELECT *, rownum
I have ~6 main classes in my application, by I usually use only one
I usually use this line to import file from out of the current folder
right now I have the following query in a stored procedure. select * from
I start a long operation (usually long query (SELECT) to database). It might take
Usually i use SQL Server as database for my project, but one of my
I use something like below to pass information from one unbound form to another
I usually use this code to add item from datebase to list view: public
I usually use Visual Studio Team System 2008 Source Control Explorer with TFS, but

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.