Java tutorial
/** * Copyright (c) 2001-2012 "Redbasin Networks, INC," [http://redbasin.org] * * This file is part of Redbasin OpenDocShare community project. * * Redbasin OpenDocShare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package dao; import util.RegexStrUtil; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import javax.sql.DataSource; import java.sql.Date; import org.springframework.beans.factory.BeanFactory; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * This class implements CarryonBlobUpdate * This is used to add blob streams (photos/documents/music ..) for a given user * This class is used to populate and share information for <code>Userpage</code> bean * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ public class CarryonBlobUpdate extends BasicDirectQuery { protected final Log logger = LogFactory.getLog(getClass()); /* private volatile DataSource dataSource; public CarryonBlobUpdate(DataSource ds) { dataSource = ds; } */ /** * This method is used to add blobstreams for a user. <code>Userpage</code> * @param blob - the blob stream * @param category - the blob type (1 - photos, 2-music, 3-video 4 - documents, 5 - archives) * @param mimeType - the mime type (image/jpeg, application/octet-stream) * @param btitle - the title for this blob * @param loginId - the loginId * @param bsize - the size of the blob * @param zoom - the zoom for the blob (used for displaying for image/jpeg) * @throws Dao Exception - when an error or exception occurs while inserting this blob in DB. * **/ public void run(Connection conn, byte[] blob, int category, String mimeType, String btitle, String loginId, long bsize, int zoom, String caption) throws BaseDaoException { byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } //long dt = System.currentTimeMillis(); // Connection conn = null; String stmt = "insert into carryon values(?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?, ?)"; PreparedStatement s = null; try { // conn = dataSource.getConnection(); s = conn.prepareStatement(stmt); s.setLong(1, 0); // entryid s.setLong(2, new Long(loginId)); // loginid s.setInt(3, new Integer(category)); // category s.setString(4, mimeType); // mimetype s.setString(5, btitle); // btitle // s.setDate(6, new Date(dt)); // s.setDate(6, CURRENT_TIMESTAMP()); s.setBytes(6, blob); s.setLong(7, bsize); s.setInt(8, new Integer(zoom)); s.setInt(9, 0); // hits s.setBytes(10, capBytes); // caption s.executeUpdate(); } catch (SQLException e) { logger.error("Error adding a blob.", e); throw new BaseDaoException("Error adding a blob " + e.getMessage(), e); } } }