Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How do you find out if a table exists (via JDBC)

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In a program I would like to write errors to a temporary table. Since it might not exist at start time, I want to check, if it is there, before writing to it. If it isn't, I might create a new one.
Is there somewhere in Java a method like "boolean tableExists(String tableName)"
Markus
p.s. It's always nice to return to the fireplace for half an hour, warm up the mind and cheer up the spirit with that funny and extraordinary design.
tx for keeping the fire running. Really
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DatabaseMetaData.getTables method - warning: some databases need the tablename and parameters in all upper case
other way - put its own try/catch block on the table creation DDL

Jamie
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if u want to temporary table then it shud be done like this
 
mark baum
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jamie Robertson:
DatabaseMetaData.getTables method - warning: some databases need the tablename and parameters in all upper case
other way - put its own try/catch block on the table creation DDL

Jamie


I tried to use getTables() like this:
public boolean isTableExisting(String tableName) throws DB_Exception{
boolean tableExists = false;
String[] types = {"TABLE"};
try {
ResultSet tableNames = databaseMetaData_.getTables(null,"%", tableName , null); // instead of types
tableExists = true;
} catch (SQLException e) {
throw new DB_Exception("DBHandler.isTableExisting - SQLEXception: "+" sqlState "+e.getSQLState()+" errorcode: "+e.getErrorCode());
}
return tableExists;
}
but the method threw the SQLException (even when the tableName was written in upper case, as you suggested)
SQLEXception: sqlState S1C00 errorcode: 106
I found S1C00 stands for "Optional feature not implemented"
Does this mean the Paradox (vers 7) driver or db does not implement a method for that call or have I been doing something wrong?
reply
    Bookmark Topic Watch Topic
  • New Topic