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

📄 gbs_mmifdetail_db.java

📁 对日软件外包 为东芝做的一个全球商业管理系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		sqlSel.append("   T_TEMP ");
		sqlSel.append(" WHERE ");
		sqlSel.append("   SEQ_NO =" + seqNo);

		ResultSet rset = null;
		Statement st = null;
		PreparedStatement pstmt = null;
		BLOB blob = null;
		BLOB blobin = null;
		String fileName = "";

		try {
			int ret = 0;
			ReturnValue returnValueD = deleteAttachmentFile(in, conn);
			if (returnValueD.isError()) {
				if (returnValueD.isBussinessError()) {
					messageList.addAll(returnValue.getMessageList());
					returnValue.setBussinessError();
				}
				returnValue.setErrorCode(returnValue.getErrorCode());
				returnValue.setErrorMessage(returnValue.getErrorMessage());
			}

			st = conn.createStatement();
			rset = st.executeQuery(sqlSel.toString());
			if (rset.next()) {
				blob = (BLOB) rset.getBlob("ATTACHMENT_FILE");
				fileName = rset.getString("ATTACHMENT_FILE_NAME");
			} else {
				ret = -1;
			}

			String strSql = "";
			StringBuffer sql = new StringBuffer();

			if (ret >= 0) {

				//start sql edit   ================================
				sql.append(" SELECT ");
				sql.append(" 		ATCH_FILE,");
				sql.append(" 		ATCH_FILE_NAME");
				sql.append(" FROM ");
				sql.append(" 		M_MIF");
				sql.append(" WHERE ");
				sql.append(" 		CUSTOMER_ID      = '" + in.getCustomerId() + "'");
				sql.append(" AND	PRODUCT_CATEGORY = '" + in.getProductCategory() + "'");
				sql.append(" AND	SUBSIDIARY_CODE  = '" + in.getSubsidiaryCode() + "'");
				sql.append(" AND	COUNTRY_CODE     = '" + in.getCountryCode() + "'");
				sql.append(" 		FOR UPDATE ");
				strSql = sql.toString();
				rset = st.executeQuery(strSql);
				if (rset.next()) {
					blobin = (BLOB) rset.getBlob("ATCH_FILE");
				} else {
					ret = -1;
				}
			}
			if (ret == 0) {
				sql = new StringBuffer();
				strSql = "";
				//start sql edit   ================================
				sql.append(" UPDATE ");
				sql.append("		M_MIF ");
				sql.append(" SET ");
				sql.append(" 		ATCH_FILE = ? ,"); //揧晅僼傽僀儖
				sql.append(" 		ATCH_FILE_NAME = ?"); //揧晅僼傽僀儖柤
				sql.append(" WHERE ");
				sql.append(" 		M_MIF.CUSTOMER_ID = ?");
				sql.append(" AND	M_MIF.PRODUCT_CATEGORY = ?");
				sql.append(" AND	M_MIF.SUBSIDIARY_CODE = ?");
				sql.append(" AND	M_MIF.COUNTRY_CODE = ?");
				//end sql edit   ================================

				//print sql
				System.out.println("[INFO] sql = " + sql.toString());

				strSql = sql.toString();
				pstmt = conn.prepareStatement(strSql);

				OutputStream out = blobin.getBinaryOutputStream();
				InputStream inStream = blob.getBinaryStream();
				byte[] buf = new byte[1024];
				int byteRead = 0;
				while ((byteRead = inStream.read(buf)) > 0) {
					out.write(buf, 0, byteRead);
				}
				out.close();
				inStream.close();

				pstmt.setBlob(1, blobin);
				pstmt.setString(2, fileName);
				pstmt.setString(3, in.getCustomerId());
				pstmt.setString(4, in.getProductCategory());
				pstmt.setString(5, in.getSubsidiaryCode());
				pstmt.setString(6, in.getCountryCode());
				ret = pstmt.executeUpdate();
				returnValue.setDataValue(new Integer(ret));
			}
		} catch (Exception exception) {
			System.out.println("[Error Happen!]");
			System.out.println("[Start Trace]");
			exception.printStackTrace();
			System.out.println("[End Trace]");
			throw exception;
		} finally {
			//release db
			try {
				if (rset != null) {
					rset.close();
				}
				if (pstmt != null) {
					pstmt.close();
				}
				if (st != null) {
					st.close();
				}
			} catch (SQLException se) {
				System.out.println("[Error Happen!]");
				System.out.println("[Start Trace]");
				se.printStackTrace();
				System.out.println("[End Trace]");
				throw se;
			}
		}
		return returnValue;
	}

	/**
	 * get AttachmentFile
	 * @return    ReturnValue
	 * @exception Exception    Exception for information of other errors
	 * @since 2004/08/09
	 */

	public ReturnValue getAttachmentFile( GBS_MMif_stBean in , HttpServletResponse response)throws Exception{
		//Add by Gxk 2004/09/10 Start
		in.setAtchFileName(BaseCommonCheck.convertSql(in.getAtchFileName()));
		in.setCountryCode(BaseCommonCheck.convertSql(in.getCountryCode()));
		in.setCreateUser(BaseCommonCheck.convertSql(in.getCreateUser()));
		in.setCustomerId(BaseCommonCheck.convertSql(in.getCustomerId()));
		in.setCustomerName(BaseCommonCheck.convertSql(in.getCustomerName()));
		in.setProductCategory(BaseCommonCheck.convertSql(in.getProductCategory()));
		in.setRemarks(BaseCommonCheck.convertSql(in.getRemarks()));
		in.setSubsidiaryCode(BaseCommonCheck.convertSql(in.getSubsidiaryCode()));
		in.setUpdateUser(BaseCommonCheck.convertSql(in.getUpdateUser()));
		//Add by Gxk 2004/09/10 End

		ReturnValue returnValue = new ReturnValue();
		MessageList messageList = new MessageList();
		returnValue.setMessageList( messageList );
		
		StringBuffer sql = new StringBuffer();
		//start sql edit   ================================
		sql.append( " SELECT");
		sql.append( " 		 ATCH_FILE,");		//揧晅僼傽僀儖
		sql.append( " 		 ATCH_FILE_NAME");	//揧晅僼傽僀儖柤
		sql.append( "   FROM " );
		sql.append( " 		 M_MIF " );
		sql.append( "  WHERE  " );
		sql.append( " 		 CUSTOMER_ID      = '" + in.getCustomerId() + "'" );
		sql.append( "   AND  PRODUCT_CATEGORY = '" + in.getProductCategory() + "'" );
		sql.append( "   AND  SUBSIDIARY_CODE   = '" + in.getSubsidiaryCode() + "'" );
		sql.append( "   AND  COUNTRY_CODE     = '" + in.getCountryCode() + "'" );
		
		//end sql edit   ================================
		
		//print sql
		System.out.println( "[INFO] sql = " + sql.toString() );
		
		ResultSet rset = null;
		Connection conn = null;
		Statement st = null;
		try{
			conn = this.datasource.getConnection();
			st = conn.createStatement();
			rset = st.executeQuery(sql.toString());
			if(rset.next() == true){
				BLOB blob = (BLOB) rset.getBlob( "ATCH_FILE" );
				String fileName  = rset.getString( "ATCH_FILE_NAME" );
				response.setContentType("APPLICATION/OCTET-STREAM");
				fileName = new String(fileName.getBytes("shift_jis"),"ISO8859-1");
				String disHeader = "Attachment;Filename=" + fileName ;
				response.setHeader("Content-Disposition", disHeader);
				ServletOutputStream os=response.getOutputStream();
				InputStream is = blob.getBinaryStream();
				byte[] data = new byte[ blob.getBufferSize() ];
				int bytesRead = 0;
				int byteSum = 0;
				while (( bytesRead = is.read( data) ) != -1 ){
					byteSum += bytesRead;
					os.write( data, 0, bytesRead );
				}
				response.setContentLength( byteSum );
				os.flush();
				response.flushBuffer();
				is.close();
				os.close();
			}			
		 }catch (Exception exception) {			
			System.out.println("[Error Happen!]");
			System.out.println("[Start Trace]");
			exception.printStackTrace();
			System.out.println("[End Trace]");
			throw exception;
		 }finally {
			//release db
			try {
				if (rset != null) {
					rset.close();
				}
				if (st != null) {
					st.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (SQLException se) {
				throw se;
			}
		}
		
		return returnValue;
	}

	/**
	 * delete *  from M_MIF and M_MIF_DETAIL
	 * @return		GBS_MMif_stBean in
	 * @exception	Exception    Exception for information of other errors
	 * @since		2004/08/09
	 */
	public ReturnValue deleteMifDetail(GBS_MMif_stBean in)throws Exception{
		
		//Add by Gxk 2004/09/10 Start
		in.setAtchFileName(BaseCommonCheck.convertSql(in.getAtchFileName()));
		in.setCountryCode(BaseCommonCheck.convertSql(in.getCountryCode()));
		in.setCreateUser(BaseCommonCheck.convertSql(in.getCreateUser()));
		in.setCustomerId(BaseCommonCheck.convertSql(in.getCustomerId()));
		in.setCustomerName(BaseCommonCheck.convertSql(in.getCustomerName()));
		in.setProductCategory(BaseCommonCheck.convertSql(in.getProductCategory()));
		in.setRemarks(BaseCommonCheck.convertSql(in.getRemarks()));
		in.setSubsidiaryCode(BaseCommonCheck.convertSql(in.getSubsidiaryCode()));
		in.setUpdateUser(BaseCommonCheck.convertSql(in.getUpdateUser()));
		//Add by Gxk 2004/09/10 End
		
		ReturnValue returnValue = new ReturnValue();
		MessageList messageList = new MessageList();
		returnValue.setMessageList( messageList );

		StringBuffer sql =  new StringBuffer();

		
	/////////////////////////////////////////////////////////////////////////////
	//EDIT SQL
		sql.append( " SELECT ");
		sql.append( " 			CUSTOMER_ID ");
		sql.append( " FROM ");
		sql.append( " 			M_MIF ");
		sql.append( " WHERE " );
		sql.append( " 			M_MIF.CUSTOMER_ID 	   = '" + in.getCustomerId() + "'" );
		sql.append( " AND 		M_MIF.PRODUCT_CATEGORY = '" + in.getProductCategory() + "'" );
		sql.append( " AND 		M_MIF.SUBSIDIARY_CODE  = '" + in.getSubsidiaryCode() + "'" );
		sql.append( " AND 		M_MIF.COUNTRY_CODE     = '" + in.getCountryCode() + "'" );
		sql.append( " FOR UPDATE " );
		//print sql
		System.out.println( "[INFO] sql = " + sql.toString() );
		Connection conn = null;
		ResultSet rset = null;
		Statement st = null;
		String strSql = "";
		PreparedStatement pstmt = null;
		int bresult = 0;
		try{
			conn = this.datasource.getConnection();
			strSql = sql.toString();
			st = conn.createStatement();
			rset = st.executeQuery( strSql );
			if(!rset.next()){
				bresult = -1;
				messageList.setMessage("", "", "10000002",Integer.MIN_VALUE );
				returnValue.setBussinessError();
			}
			if ( bresult == 0 ){
				sql = new StringBuffer();
				strSql = "";
				//start sql edit   ================================
				//delete form M_MIF
				sql.append( "  DELETE FROM M_MIF" );
				sql.append( "  WHERE" );
				sql.append( "   		CUSTOMER_ID 	 = '"+ in.getCustomerId() + "'" );	
				sql.append( "  AND 		PRODUCT_CATEGORY = '" + in.getProductCategory() + "'" );
				sql.append( "  AND 		COUNTRY_CODE     = '" + in.getCountryCode() + "'" );
				sql.append( "  AND 		SUBSIDIARY_CODE  = '" + in.getSubsidiaryCode() + "'" );

				//end sql edit   ================================

				//print sql				
				System.out.println( "[INFO] sql = " + sql.toString() );	
					
				strSql = sql.toString();
				//st = conn.createStatement();
				pstmt = conn.prepareStatement(strSql);
				//bresult= st.execute(strSql);
				bresult = pstmt.executeUpdate();
				if ( bresult > 0 ){
					//delete from M_MIF_DETAIL
					bresult = deleteMifEntryDetail( in, conn );
					if ( bresult > 0 ){
						conn.commit();			
					}else{
						conn.rollback();
					}
				}	
			
			}
		}catch (Exception exception) {
			System.out.println("[Error Happen!]");
			System.out.println("[Start Trace]");
			exception.printStackTrace();
			System.out.println("[End Trace]");
			throw exception;
		}finally {
			//release db
			try {
				if ( rset != null ) {
					rset.close();
				}
				if ( pstmt != null ){
					pstmt.close();
				}
				if ( st != null ) {
					st.close();
				}

⌨️ 快捷键说明

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