import java.io.FileInputStream; import java.io.InputStream; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import com.adeptia.indigo.security.AuthUtil; import com.adeptia.indigo.services.transform.ScriptedService; import com.adeptia.indigo.services.transport.connector.DatabaseConnectionInfo; import com.adeptia.indigo.storage.EntityManager; import com.adeptia.indigo.storage.EntityManagerFactory; import com.adeptia.indigo.storage.TypedEntityId; import com.adeptia.indigo.system.Context; import com.adeptia.indigo.utils.JdbcUtils; String databaseInfoId = ""; String sqlScriptPath = ""; Connection conn = null; Statement st = null; try { FileInputStream fis = new FileInputStream(sqlScriptPath); int h = 0; byte[] data = new byte[1024]; StringBuffer sqlBuffer = new StringBuffer(); while ((h = fis.read(data)) != -1) { sqlBuffer.append(new String(data, 0, h)); } // get connection info and create database connection EntityManager entityManager = EntityManagerFactory .getEntityManager(DatabaseConnectionInfo.class, AuthUtil.getAdminSubject()); DatabaseConnectionInfo dbInfoEntity = (DatabaseConnectionInfo) entityManager .retrieve(new TypedEntityId(databaseInfoId, "DatabaseConnectionInfo")); conn = JdbcUtils.getConnection(dbInfoEntity, AuthUtil.getAdminSubject()); st = conn.createStatement(); // execute the query boolean result = st.execute(sqlBuffer.toString()); context.put("CustomPluginResult", result); } catch (Exception e) { String error = "Error while executing the SQL query. Reason - " + e.getMessage() + ". Please see the error trace for more details."; context.put("CustomPluginError", error); System.out.println(error); e.printStackTrace(); } finally { try { if (st != null) { st.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { System.out .println("Error while close the database connection. Please see the error trace for details"); e.printStackTrace(); } }