Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
mark baum
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • 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
 
prabhat kumar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic