⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbtools.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
// $Id: DBTools.java,v 1.3 2002/05/06 17:51:12 djilli Exp $////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////              . . . i n   j a h i a   w e   t r u s t . . .//////  DBTools////  02.04.2001  MJ  added in jahia.//package org.jahia.admin.components;import java.sql.*;                                  // SQLimport javax.servlet.*;			                    // ServletExceptionimport javax.servlet.http.*;			            // HttpServletRequest, HttpServletResponseimport org.jahia.registries.*;                  // ServicesRegistryimport org.jahia.services.database.*;           // Databaseimport org.jahia.exceptions.*;                  // JahiaException    public class DBTools    {    /**     * write a log entry to the database     *     * this method belongs in org.jahia.services.audit.JahiaDBAuditLogManager     * it is here for want of a convenient way to pass a JahiaEvent, with reference     * to ParamBean, to the manager from the Application Manager Service.     *     * @author Mikhael Janson     * @param   entryID     * @param   time     * @param   userNameStr     * @param   objectTypeStr     * @param   objectIDStr     * @param   operationStr     * @param   contentStr     */    protected static boolean insertAuditLogEntry ( int    entryID,                                                String timeStr,                                                String userNameStr,                                                String objectTypeStr,                                                String objectIDStr,                                                String parentObjIDStr,                                                String parentTypeStr,                                                String operationStr,                                                String contentStr )    throws JahiaException    {        JahiaDBPoolService           mDBPoolService  = null;        String     MSG_INTERNAL_ERROR      = new String ("Jahia Administration internal error");        // Try to get the DB Pool Service        ServicesRegistry registry = ServicesRegistry.getInstance();        if (registry != null)        {            mDBPoolService = registry.getDBPoolService();            if (mDBPoolService == null) {                throw new JahiaException (MSG_INTERNAL_ERROR, "JahiaAdministration could not get the DB Connection Pool Service instance.",                                            JahiaException.SERVICE_ERROR, JahiaException.CRITICAL);            }        } else {            throw new JahiaException (MSG_INTERNAL_ERROR, "JahiaAdministration could not get the Service Registry instance.",                                      JahiaException.REGISTRY_ERROR, JahiaException.CRITICAL);        }        Connection dbConn = null;        try {            dbConn = mDBPoolService.getConnection (1002);        }        catch (NullPointerException npe) {            //System.out.println  ("Null Pointer Exception, DB Pool Service instance might be null!");        }        catch (SQLException se) {            //System.out.println  ("SQL Exception: cannot get a connection.");        }        if (dbConn == null) {            return false;        }        // Get a database connection        boolean     result = true;        Statement   statement = null;        try {            statement = dbConn.createStatement();            String query = "INSERT INTO jahia_audit_log (id_jahia_audit_log, time_jahia_audit_log, username_jahia_audit_log, objecttype_jahia_audit_log, operation_jahia_audit_log, objectid_jahia_audit_log, parentid_jahia_audit_log, parenttype_jahia_audit_log, content_jahia_audit_log ) VALUES ("                                + Integer.toString(entryID)                                + ",'"   + timeStr                                + "','"  + userNameStr                                + "',"   + objectTypeStr                                + ",'"   + operationStr                                + "',"   + objectIDStr                                + ","    + parentObjIDStr                                + ","    + parentTypeStr                                + ",'"   + contentStr + "')";            ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,query);        }        catch (SQLException sqlEx) {            //System.out.println ("SQL Exception occured!" + sqlEx.getMessage());            result = false;        }        finally {        if ((mDBPoolService != null) && (dbConn != null)) {            try {                mDBPoolService.freeConnection (dbConn);            }            catch (SQLException se) {                // FIXME -MJ- : Don't know yet what to do with this exception.                //                 It should be logged somewhere !            }        }        // Close the opened statement        try {            if (statement!=null) {                statement.close();            }        }        catch (SQLException se) {            // FIXME -MJ- : Don't know yet what to do with this exception.            //                 It should be logged somewhere !        }        }        return result;    }} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -