This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes SQL Trigger failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Trigger failure" Watch "SQL Trigger failure" New topic
Author

SQL Trigger failure

Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Hi!
Could someone please tell me why sql trigger in the below code fails. Please guide me with corrected trigger code. Database is Java DB.
Thanks in advance!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

Hi.

What happens? Any error messages? What fails?

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Thanks for your reply!
The trigger fails to work. There are no error messages.
My attempt is simple:
Whenever I insert a value in table one, immediately the same data should be inserted in table two as well.

I'm new to SQL. I'm still trying to know why it has failed.
Thanks in advance for any help.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8


I don't think that's the correct format for an INSERT statement which doesn't assign values to all columns.
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

It's been more than 12 hours that I've started working with this small program. Yes, I just now got to know my mistake!
There is nothing wrong with the code but the order of statements. The below code generates what I wanted:

Insert statements should come after trigger.
Thanks for your replies!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

Ah Yes. You inserted the record before the trigger was created. Now I see it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQL Trigger failure