Thanks to everyone, finally, I got a method that solves this problem, thanks for your suggestions, the code is as follows:
public boolean existViewInDB(String viewName) {
logger.debug("[boolean existViewInDB(String viewName[" + viewName
+ "])]");
boolean existView = false;
try {
String sql =
"SELECT count(*) FROM user_views WHERE view_name = :viewName";
SQLQuery query = getSession().createSQLQuery(sql);
query.setString("viewName", viewName);
BigDecimal totalOfViews = (BigDecimal) query.uniqueResult();
existView = (totalOfViews.longValue() > 0);
} catch (Exception e) {
logger.error(e, e);
}
logger.debug("Exist View [" + viewName + "] ? -> " + existView);
return existView;
}
It works!:)
source
share