Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking the table already present or not  RSS feed

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
How will i know that the table which i am creating is allready present in the database of Access.
with best regards,
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may be able to use the DataBasemetadata object to list the tables and then check if it's there. OTOH, you can just create it and see if it throws an exception that the table already exists.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use Bosun's suggestion number 2:
create the table, if an exception is thrown, I assume that it already exists so I truncate it ( delete all rows ) to make sure I'm starting with an empty table.
Jamie
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which exception do you look for? SQLException?
 
Sanjay Jadhav
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
Yes it's work with DatabaseMetaData, using the exception way is somewhat missleading.
with best regards,
Sanjay
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sanjay Jadhav:
Hi..
Yes it's work with DatabaseMetaData, using the exception way is somewhat missleading.
with best regards,
Sanjay


Caution with this method: relying on every user to have the same odbc drivers is even more missleading. Many ODBC drivers (especially with access) come up short when it comes to DatabaseMetaData ( not implemented ), but you can always guarantee that DML/DDL will work with every version.
Unless every user has the same access driver, and you can guarantee that the DatabaseMetaData method is implemented, stick with the exception catching
Jamie
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!