3
出於某種原因,我們需要運行數據庫原生查詢而不是靈活的查詢。爲了運行這些查詢,我們需要數據庫連接,因此我們如何從Hybris獲取jdbcTemplate或DataSource對象。Hybris數據庫連接
出於某種原因,我們需要運行數據庫原生查詢而不是靈活的查詢。爲了運行這些查詢,我們需要數據庫連接,因此我們如何從Hybris獲取jdbcTemplate或DataSource對象。Hybris數據庫連接
這是一個腳本常規,可以實現這一點的例子:
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!"
很高興知道.. – HybrisFreelance
對於到底是什麼在更多的細節?您還可以在靈活搜索中使用數據庫相關條件。如果代碼未被識別爲靈活搜索,則它將按照在數據庫中的原樣傳遞。 –