Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to call java functions from sql server trigger

Author  Topic 

Roka
Starting Member

5 Posts

Posted - 2010-03-23 : 12:28:43
I need to call some java functions from sql server using a trigger. Is there any way to solve this requirement?, if yes, can you share it to me?, otherwise, is there any other way to implement that functionality?.

I send this message using this forum because i cant create a new one, i dont know how to, and there is no other forum where i can post my question.

thanks in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-23 : 12:32:43
what are functions doing?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Roka
Starting Member

5 Posts

Posted - 2010-03-23 : 12:36:36
the java functions start a process with an external device, it must be executed when data with especific information is inserted in sql server, so thats because i use a trigger for insert
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-23 : 12:42:11
its not a good idea to use trigger for this. it would better for you to schedule a periodic task which checks for relevant data and then do processing with functions

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Roka
Starting Member

5 Posts

Posted - 2010-03-23 : 12:49:12
firstable thank you for your help and your responses, the problem is that i need to do the task immediately after the information is inserted in the table, for this reason im using a trigger, i mean, the trigger calls a stored procedure which has to call the java method, i know the java method must be static, but the problem is that i do not know how to call the java method from the sql server stored procedure
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-23 : 12:54:39
try using xp_cmdshell if you've no other way

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-03-23 : 12:54:45
What do you mean by trigger calls a stored procedure and also instead of sp calling java method shouldn't it be that java method should call the sp?

PBUH
Go to Top of Page

Roka
Starting Member

5 Posts

Posted - 2010-03-23 : 13:01:34
visakh16,

thanks once again, i´ve tried the xp_cmdshell a few days ago, i tried it by writing the following line:

xp_cmdshell ´calc.exe´

then when i execute this line, sql server starts executing query and it still in the same process a lot of time, then i have to stop query, i also try to give the complete path but the response is the same, the last time i tried with the following line:

xp_cmdshell ´java Test´ and the response was that the class could not be found, the same response when i give it the complete path

so i dont know if im using xp_cmdshell in the wrong way
Go to Top of Page

Roka
Starting Member

5 Posts

Posted - 2010-03-23 : 13:05:19
Idera

The execution of the method must be done from the sql server trigger, so by this way i would like to create a sp where i execute or call the java method, and the trigger invokes the sp when a new row with some especific information is inserted, so thats because i need a trigger for insert.

It could not be done from java.

Thanks

Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2010-03-23 : 13:26:31
As Visakh has mentioned, I would explore the option of just using the trigger to put the data into a table queue and then run a Java app to process the queue.

If you really need to call a Java method from within a trigger maybe you could try experimenting with using a webservice. eg:
1. Write a Java webservice to expose the java method.
2. Write a CLR function to call the webservice.
3. Call the CLR function from within the trigger.

You could also look at calling the Java method from the middle tier in the same transaction as inserting into the DB.

Go to Top of Page
   

- Advertisement -