Código:
StringBuffer triggerQuery = new StringBuffer(); try { InputStream is = getClass().getClassLoader().getResourceAsStream("imagen/trigger.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while((line = br.readLine())!= null){ triggerQuery.append(line); } executeLine(triggerQuery.toString()); } catch(Exception E){ } }
y el contenido de mi archivo de texto es el siguiente
Código:
DROP TRIGGER IF EXISTS ACTCODIGO; DELIMITER | CREATE TRIGGER actcodigo BEFORE INSERT ON BC_ARTICULOS FOR EACH ROW BEGIN DECLARE digito INT DEFAULT 0; DECLARE resultado INT DEFAULT 0; DECLARE IDN INT DEFAULT 0; DECLARE NUMPREV VARCHAR(30) DEFAULT 0; IF NEW.BARCODE IS NULL THEN SET IDN = (SELECT MAX(ID) FROM BC_ARTICULOS); IF IDN IS NULL THEN SET IDN = 1; ELSE SET IDN = (SELECT MAX(ID) FROM BC_ARTICULOS) +1; END IF; SET NUMPREV = 750000000000 + IDN; SET DIGITO = 10-(((substr(NUMPREV,2,1)+substr(NUMPREV,4,1)+substr(NUMPREV,6,1)+substr(NUMPREV,8,1)+substr(NUMPREV,10,1)+substr(NUMPREV,12,1))*3)+((substr(NUMPREV,1,1)+substr(NUMPREV,3,1)+substr(NUMPREV,5,1)+substr(NUMPREV,7,1)+substr(NUMPREV,9,1)+substr(NUMPREV,11,1))))mod 10; IF DIGITO < 10 THEN SET NEW.BARCODE = CONCAT(NUMPREV,DIGITO); ELSE SET NEW.BARCODE = CONCAT(NUMPREV,'0'); END IF; END IF; END | DELIMITER ;