• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

CHECK IF A TABLE ALREADY EXISTS

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have been able to create a table in a database using java. now i want to check if a specific table exists in that database and if that table exists, then just insert values in it or else create a new table. PLEASE HELP ME OUT!!!
Thanks in advance for any help
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at Connection.getMetaData().
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can do with using the getTables method of DatabaseMetaData Interface. See the complete signature of this method on Java Doc
 
author
Posts: 4342
40
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do "SELECT 1 FROM [TABLE_NAME]" although then you'd have to do exception trapping which should be avoided if the table not existing is a common event.
 
Zaafir Barahim
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to you all. It works. Now i want to get all the tables in the database or just count the number of tables exists in my database. How do i do it. Iv got a code and when i execute it, i get an error saying that the feature is not present in my ACCESS DATABSE. Please help me out for new codes or for the prob. Thanks
 
Zaafir Barahim
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could i get also the data or the row count for each table found in the database
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The query SELECT TNAME, ROWNUM FROM TAB WHERE TABTYPE = 'TABLE' can be used to get the table name and the row number of that tablename.

Hope this may help you.
 
Zaafir Barahim
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it didnt work. Actually can i get some more information about what to replace in the select query. i have a database name "DATABASE", and i have 2 tables named "TABLE1" and "TABLE2". i am using MICROSOFT ACCESS DATABASE and JAVA to get all the tables in the database and the data inside each table. please help me out!!!
 
This tiny ad is wafer thin:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic