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 java.sql.Connection; import java.sql.PreparedStatement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * This class implements GuestMessageAddQuery * Used by <code>Guestbook</code> bean * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ class GuestMessageAddQuery { protected final Log logger = LogFactory.getLog(getClass()); /** * This method is used to add guestbook information * @param conn - the connection * @param loginid - the loginid (whose guestbook is updated) * @param guestid - the guestid * @param message - the guestbook entry * @throws BaseDaoException - when error ocurrs **/ public void run(Connection conn, String loginid, String guestid, String message) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement("insert into guestbook values(0, " + loginid + ", " + guestid + ", CURRENT_TIMESTAMP(),'" + message + "')"); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured executing insert into guestbook ", e); } } /* public GuestMessageAddQuery(DataSource ds) { setDataSource(ds); // this is spring one setSql("insert into guestbook values (?, ?, ?, ?, ?)"); declareParameter(new SqlParameter(Types.INTEGER)); declareParameter(new SqlParameter(Types.BIGINT)); declareParameter(new SqlParameter(Types.BIGINT)); declareParameter(new SqlParameter(Types.TIMESTAMP)); declareParameter(new SqlParameter(Types.VARCHAR)); compile(); } public int run(String loginid, String guestid, String message) { // long dt = new java.util.Date().getTime(); long dt = System.currentTimeMillis(); //Object[] params = new Object[] {new Integer(0), new Long(loginid), new Long(guestid), new Date(dt), message }; Object[] params = {(Object)new Integer(0), (Object)new Long(loginid), (Object)new Long(guestid), (Object)new Date(dt), (Object)message }; return update(params); } */ }