For some reason we need to run database native query instead of flexible query. For running those queries we need DB connection so how can we get the jdbcTemplate or DataSource object from Hybris.
This is an example of a script groovy that can achieve this :
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import de.hybris.platform.util.Utilities;
import de.hybris.platform.core.Registry;
Connection conn = null;
PreparedStatement pstmt = null;
try
{
conn = Registry.getCurrentTenant().getDataSource().getConnection();
pstmt = conn.prepareStatement("your sql query here...");
pstmt.execute();
}
catch (final SQLException e)
{
LOG.error("Error!!");
}
finally
{
Utilities.tryToCloseJDBC(conn, pstmt, null);
}
return "Groovy Rocks!"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With