Thank you very much! I had to do what you did, but also had to put the same 
Trigger class in the same package within my main project. It seems like it 
actually uses the Trigger in my main project, and the one within the 
classpath of the H2 Driver is just for validation?

On Tuesday, June 14, 2016 at 5:32:00 AM UTC-4, Steve McLeod wrote:
>
> Note that an IntelliJ IDEA data source is not running in the same JVM that 
> your project is running in. The data source is independent of your project 
> code, and has no awareness of it.
>
> I guess you'd have to compile your Trigger class, bundle it into a jar, 
> and add that jar to the data source config's driver files section.
>
>
>
>
> On Tuesday, 14 June 2016 05:35:17 UTC+2, Chronpwn wrote:
>>
>> I am using IntelliJ IDEA as my IDE, and they have an option where you can 
>> specify the Driver URL. I tested this connection and am able to connect to 
>> the database, but when I add a new trigger:
>>
>> public class VoteInsertTrigger extends TriggerAdapter {
>>
>>     @Override
>>     public void fire(Connection conn, ResultSet oldRow, ResultSet newRow) 
>> throws SQLException {
>>         Statement statement = conn.createStatement();
>>
>>         boolean vote = newRow.getBoolean(newRow.findColumn("vote"));
>>         int deckId = newRow.getInt("deck_id");
>>         int value = vote ? 1 : -1;
>>
>>         String sql = "UPDATE DECKS SET DECKS.RATING=DECKS.RATING + %d WHERE 
>> DECKS.ID=%d";
>>         sql = String.format(sql, value, deckId);
>>
>>         statement.executeUpdate(sql);
>>     }
>> }
>>
>>
>> With the command:
>>
>> CREATE TRIGGER vote_insert
>> BEFORE INSERT
>> ON USERS_VOTES
>> FOR EACH ROW
>> CALL "com.chronpwn.chronpwn.data.VoteInsertTrigger"
>>
>>
>> it fails with: "cause: "org.h2.message.DbException: Class 
>> ""VoteInsertTrigger"" not found"
>>
>> I rebuilt my entire project which puts the VoteInsertTrigger class in my 
>> classpath.
>>
>> When you mention "The trigger class must be available in the classpath 
>> of the database engine," my entire project + the H2 jar are on the 
>> classpath, so I would appreciate some insight on why this is happening. 
>> Thank you.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to