0

I wrote a java program to insert and update data for oracle database. i need to DISABLE some triggers before insert or update data. also need to ENABLE previously DISABLED triggers after insert or update data. i wrote two sql scripts as pre_script.sql and post_script.sql to DISABLE and ENABLE triggers.

How could i run these files using java ? is there any method to pass these sql files for execute in java ?

Bishan
  • 15,211
  • 52
  • 164
  • 258
  • possible duplicate of [run oracle sql script from java](http://stackoverflow.com/questions/200513/run-oracle-sql-script-from-java) – Alex Poole May 25 '12 at 09:02

2 Answers2

2

The simplest option would be to create your SQL scripts as stored procedures or functions in the database, which would then just require a simple call from Java to execute them.

CallableStatement cs = conn.prepareCall("{ call pre_script_as_func() }");
cs.execute();

// do inserts, updates 

cs = conn.prepareCall("{ call post_script_as_func() }");
cs.execute();
Datajam
  • 4,141
  • 2
  • 23
  • 25
0
import java.io.*;
import java.sql.*;

Assuming a connection object of conn

Create a SQL statement from connection object:

Statement DMLString conn.createStatement();

Create a string variable and populate with alter trigger statement:

String sql = "ALTER TRIGGER [TRIGGER_NAME] DISABLE";

Execute the SQL against the DB

String  result = DMLString.execute(sql.toString());