Discussion Locked

JDBC:does nt let me create 2 tables!

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have made an awt interface.in that i have 2 buttons to create their respective tables in database.the problem is that when i create table B immediately after i create table a i get an sql exception.tab b has a foreign key of tab a(id). i need to close my interface and then create table b. then it gets created.

4 replies

by saurabhambekar

It is clear that, when u try to create table B (which has a foreign key for table A), the metadata of table A is not yet available.

i dont know the exact solution to this problem, but let few seconds pass and then create table B. i know this sounds stupid, but give it a try.

Or

close and reopen the connection before creating table B and then check the result.

by martin simons

The first thing to look at, wuld be make sure that the table creation from button a is actually committed. do you have a console to the database so that you can look and see that the table exists after pushing button a, but before closing the application. It seems to me that problem lies in the commit. The sql executed from the first command will not be available to other db sessions until after a commit has been run.

by dancoo

Martin is right. Your code has to explicitly commit the first table creation before you can do the 2nd one. You can't do them together in one batch of SQL.

This discussion is closed to new replies.