Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in using Temporary tables

 
Nila dhan
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating temporary tables in Sybase database for my application.
The query is getting executed without any issues for the first time. But when I refresh the output page, which implicily hits the server with another rquest, I get the following error

Cannot create temporary table '#TEMPTABLE'. Prefix name '#TEMPTABLE'' is already in use by another temporary table '#TEMPTABLE'.

Please suggest..

Thanks in advance
 
Campbell Ritchie
Sheriff
Pie
Posts: 49396
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the error message is self-explanatory. You are creating the same table twice (or trying to).
 
Nila dhan
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the error message is self-explanatory. My requirement is to create the temporary table only if it doesnt exist already.

Is there any check that can be performed to find if the table already exists ? If so, how to perform the check ?
 
Nila dhan
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the error message is self-explanatory. My requirement is to create the temporary table only if it doesnt exist already.

Is there any check that can be performed to find if the table already exists ? If so, how to perform the check ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes, the error message is self-explanatory. My requirement is to create the temporary table only if it doesnt exist already.

Is there any check that can be performed to find if the table already exists ? If so, how to perform the check ?

Temporary tables in Sybase are per session, so one way is to open a new connection.

The other is to interogate the database catalog to see if the current table aleady exists. You can do this using database specific T-SQL, e.g. :

Not 100% sure this will work on Sybase, my T-SQL experience is all SQL Server, but you get the gist.

You can also do this in JDBC via DatabaseMetaData. Have a look at the methods that class gives you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic