Example: PLSQL Cursor with parameters updating the current line

Here is a example how to use cursor with parameters in PLSQL accessing each row
of the given table and changing it’s value.

declare
  cursor c_funcionario(p_matricula in number) 
    is (select * from funcionario where matricula = p_matricula) for update;
begin

  for currentFuncionario in c_funcionario(2) loop
    update funcionario set salario = 300 where current of c_funcionario;
  end loop;
  
  commit;
end;

How to create a PACKAGE in oracle

PACKAGE HEADER

create or replace PACKAGE MY_PACK AS 

  /* TODO enter package declarations (types, exceptions, methods etc) here */ 
    
  PROCEDURE PROCEDURE_1(v_texto in out varchar2);
  FUNCTION FUNCTION_1(v_parametroEntrada in varchar2) return varchar2;

END MY_PACK;

PACKAGE BODY

create or replace package body MY_PACK
IS

  PROCEDURE PROCEDURE_1(v_texto in out varchar2) IS 
  BEGIN
    v_texto := 'my return';
  END PROCEDURE_1;
  
  FUNCTION FUNCTION_1(v_parametroEntrada in varchar2) return varchar2 is
  begin
    return v_parametroEntrada;
  end;

END MY_PACK;

How to send an image in email using commons-email lib

import org.apache.commons.mail.HtmlEmail;
...

  // Create the email message
  HtmlEmail email = new HtmlEmail();
  email.setHostName("mail.myserver.com");
  email.addTo("jdoe@somewhere.org", "John Doe");
  email.setFrom("me@apache.org", "Me");
  email.setSubject("Test email with inline image");
  
  // embed the image and get the content id
  URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
  String cid = email.embed(url, "Apache logo");
  
  // set the html message
  email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");

  // set the alternative message
  email.setTextMsg("Your email client does not support HTML messages");

  // send the email
  email.send();

Visit the official website: https://commons.apache.org/proper/commons-email/userguide.html

How to get as String the full stack of a exception in your application

<dependency>
  <groupId>commons-lang</groupId>
  <artifactId>commons-lang</artifactId>
  <version>2.2</version>
</dependency>
//sample of code
try {
     List<Veiculo> result = veiculoService.findAllVeiculos();
 
     List<Veiculo> listaNova = null;
 
     listaNova.add(result.get(0));
     listaNova.add(result.get(1));
     listaNova.add(result.get(2));
 
     msg.reply(Json.encode(listaNova));

 } catch (Exception e) { 
     String msgError = ExceptionUtils.getFullStackTrace(e);

     msg.fail(MessageCode.INTERNAL_SERVER_ERROR, msgError);
 }

Load properties from property file to spring.xml file

datasource.properties

datasource.driverClass=oracle.jdbc.driver.OracleDriver

datasource.jdbcUrl=jdbc:oracle:thin:@10.0.1.100:1521:xe
datasource.user=user
datasource.password=password
datasource.redis.address=127.0.0.1
datasource.redis.port=6379

c3p0.minPoolSize=5
c3p0.maxPoolSize=20	    
c3p0.acquireIncrement=1
c3p0.maxStatements=50
c3p0.idleConnectionTestPeriod=3000
c3p0.loginTimeout=300

spring.xml

<!-- load properties from property file -->
<context:property-placeholder location="classpath:datasource.properties" />

<!-- using properties from property file -->
  <bean id="myContactDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <!-- Connection properties -->
      <property name="driverClass" value="${datasource.driverClass}" />
      <property name="jdbcUrl" value="${datasource.jdbcUrl}" />
      <property name="user" value="${datasource.user}" />
      <property name="password" value="${datasource.password}" />
      
      <!-- Pool properties -->
      <property name="minPoolSize" value="${c3p0.minPoolSize}" />
      <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
      <property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
      <property name="maxStatements" value="${c3p0.maxStatements}" />
      <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" />
      <property name="loginTimeout" value="${c3p0.loginTimeout}" />
  </bean>