| Author |
CHECK IF A TABLE ALREADY EXISTS
|
Zaafir Barahim
Ranch Hand
Joined: Dec 12, 2006
Posts: 36
|
|
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
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
|
Look at Connection.getMetaData().
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Muhammad Saifuddin
Ranch Hand
Joined: Dec 06, 2005
Posts: 1318
|
|
|
you can do with using the getTables method of DatabaseMetaData Interface. See the complete signature of this method on Java Doc
|
Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3666
|
|
|
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.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
Zaafir Barahim
Ranch Hand
Joined: Dec 12, 2006
Posts: 36
|
|
|
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
Joined: Dec 12, 2006
Posts: 36
|
|
|
could i get also the data or the row count for each table found in the database
|
 |
Sujith Kanaparthi
Ranch Hand
Joined: Sep 04, 2005
Posts: 45
|
|
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
Joined: Dec 12, 2006
Posts: 36
|
|
|
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!!!
|
 |
 |
|
|
subject: CHECK IF A TABLE ALREADY EXISTS
|
|
|