【问题标题】:Hybris Database ConnectionHybris 数据库连接
【发布时间】:2017-07-06 09:44:13
【问题描述】:

出于某种原因,我们需要运行数据库原生查询而不是灵活查询。为了运行这些查询,我们需要数据库连接,所以我们如何从 Hybris 获取 jdbcTemplate 或 DataSource 对象。

【问题讨论】:

  • 究竟是为了什么?您还可以在灵活搜索中使用 DB 相对条件。如果代码未被识别为灵活搜索,它将在数据库中按原样传递。

标签: hybris


【解决方案1】:

这是一个可以实现此目的的 groovy 脚本示例:

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!"


编辑:在这篇文章中找到更多细节https://www.stackextend.com/hybris/run-native-sql-query-hybris/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多