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

📄 filemanagerdb.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    	Statement stmt = null;		ResultSet rs = null;				try {       	        			// get a connection to the db   	   		dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(1);	      	// execute the query			String query = "select * from jahia_filemgr where ownerid_jahia_filemgr=" + ownerID;						stmt = dbConn.createStatement();			debugQuery(query);			rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query);			while ( rs.next() )			{				int filemanagerID = rs.getInt("id_jahia_filemgr");				String storagePath = rs.getString("storagepath_jahia_filemgr");				fmng = new Filemanager();				fmng.setFilemanagerID(filemanagerID);				fmng.setStoragePath(storagePath);				fmng.setOwnerID(ownerID);			}		}		catch (SQLException ex) {		 	processSQLException("FilemanagerDB::getFilemanagerByOwner(id)",ex);		}      	finally      	{			try {				ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);				if ( stmt != null ) stmt.close();			} catch ( SQLException ex ) {		 		processSQLException("FilemanagerDB::  getFilemanager(ownerID) freeing connection fails",ex);			}			      	}		return fmng;   	}    //--------------------------------------------------------------------------	/**	 * return a DOM document of the Filemanager of a site	 *	 * @param int the site id	 *	 * @return JahiaDOMObject a DOM representation of this object	 *	 * @author NK	 */	public JahiaDOMObject getFileMgrAsDOM( int siteID )	throws JahiaException{			Connection dbConn = null;        Statement statement = null;		String output = null;		JahiaDBDOMObject dom = null;			    try {            String sqlQuery = "SELECT * FROM jahia_filemgr where ownerid_jahia_filemgr="+siteID;	        dbConn = getDBConnection(0);            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery );                if (rs != null) {					dom = new JahiaDBDOMObject();					dom.addTable("jahia_filemgr",rs);					return dom;				}			}	    } catch (SQLException se) {	        String errorMsg = "Error in getFileMgrAsDOM(int siteID) : " + se.getMessage();            JahiaConsole.println( "JahiaFilemanagerDB", errorMsg );	        throw new JahiaException(   "Cannot load filemanager from the database",	                                    errorMsg, JahiaException.DATABASE_ERROR,	                                    JahiaException.CRITICAL );	    } finally {            closeDBConnection (dbConn);            closeStatement (statement);        }		return dom;	}    //--------------------------------------------------------------------------	/**	 * return a DOM document of the Filemanager files of a site	 *	 * @param int the site id	 *	 * @return JahiaDOMObject a DOM representation of this object	 *	 * @author NK	 */	public JahiaDOMObject getFileMgrFilesAsDOM( int siteID )	throws JahiaException{			Connection dbConn = null;        Statement statement = null;		String output = null;		JahiaDBDOMObject dom = null;		    try {			Filemanager fmng = FilemanagerDB.getInstance().getFilemanagerByOwner(siteID);			if ( fmng == null ) {				dom = new JahiaDBDOMObject();				dom.addTable("jahia_filemgr_files",null);				return dom;			}            String sqlQuery = "SELECT * FROM jahia_filemgr_files where filemgrid_jahia_file="+fmng.getFilemanagerID();	        dbConn = getDBConnection(0);            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery );                if (rs != null) {					dom = new JahiaDBDOMObject();					dom.addTable("jahia_filemgr_files",rs);					return dom;				}			}	    } catch (SQLException se) {	        String errorMsg = "Error in getFileMgrFilesAsDOM(int siteID) : " + se.getMessage();            JahiaConsole.println( "JahiaFilemanagerDB", errorMsg );	        throw new JahiaException(   "Cannot load filemanager files from the database",	                                    errorMsg, JahiaException.DATABASE_ERROR,	                                    JahiaException.CRITICAL );	    } finally {            closeDBConnection (dbConn);            closeStatement (statement);        }		return dom;	}    //-------------------------------------------------------------------------    private Connection getDBConnection (int debugInfo)    {        Connection dbConn = null;        try {            if ( debugInfo != 0 ){            	dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (debugInfo);            } else {            	dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection ();			}        }        catch (NullPointerException ex) {            JahiaConsole.println ("JahiaPagesDB", "Null Pointer Exception, DB Pool Service instance might be null!");        }        catch (SQLException ex) {            JahiaConsole.println ("JahiaPagesDB", "SQL Exception: cannot get a connection.");        }        return dbConn;    }    //-------------------------------------------------------------------------    private void closeDBConnection (Connection dbConn)    {        if (dbConn != null) {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection (dbConn);            }            catch (SQLException sqlEx) {                // just create an exception without raising it, just to notify it                // in the logs.                JahiaException je = new JahiaException ("Cannot free resources",                        "Cannot free resources", JahiaException.DATABASE_ERROR,                        JahiaException.WARNING);            }            catch (NullPointerException ex) {                JahiaConsole.println ("JahiaPagesDB", "Null Pointer Exception, DB Pool Service instance might be null!");            }        }    }    //-------------------------------------------------------------------------    private void closeStatement (Statement statement)    {        // Close the opened statement        try {            if (statement!=null) {                statement.close();            }        }        catch (SQLException sqlEx) {            // just create an exception without raising it, just to notify it            // in the logs.            JahiaException je = new JahiaException ("Cannot close a statement",                    "Cannot close a statement", JahiaException.DATABASE_ERROR,                    JahiaException.WARNING);        }    }	/**	 * Method filter	 * Filter special caracters	 *	 * @param input String to filter	 * @return a filtered string	 */      	public static String filter(String input) {		StringBuffer filtered = new StringBuffer ( input.length() );		char c;		for ( int i=0 ; i<input.length(); i++ )		{			c = input.charAt(i);			if ( c == '\'' ) {				 filtered.append( "&#39;" );			} else if ( c== '"' ) {				 filtered.append( "&#34;" );			} else {				 filtered.append(c);			}		}		return (filtered.toString());   	}		/**	 * Method toConsole	 * For debug purpose	 * Write a msg to the console	 *	 * @param msg the message to display	 */	 public void toConsole(String msg){	 	if (false){	 		// System.out.println(msg);	    }	 }     	/**	 * Method debugQuery	 * Outout the query for debug purpose	 *	 * @param query	 */      	public static void debugQuery(String query) {   		if ( m_debugQuery ) {	   		JahiaConsole.println("FilemanagerDB", query);   		}   	}	/**	 * Method processSQLException	 * For debug purpose	 *	 * @param func the name of the calling method	 * @param SQLException	 */	public void processSQLException (String func, SQLException ex) {   		if ( m_debugQuery ) {			while (ex != null) {				JahiaConsole.println("FilemanagerDB","SQL EXCEPTION in function [" + func + "]: SqlState = " + ex.getSQLState() + "   Error code = " + ex.getErrorCode() + "   Error msg = " + ex.toString());				ex = ex.getNextException();			}		}	}}

⌨️ 快捷键说明

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