Java tutorial
/******************************************************************************* * Copyright (c) 2013 BowenCai. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * BowenCai - initial API and implementation ******************************************************************************/ package net.freechoice.model.orm; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import net.freechoice.model.FC_Account; import org.springframework.jdbc.core.PreparedStatementCreator; /** * * @author BowenCai * */ public class Map_Account implements IMapper<FC_Account> { public FC_Account mapRow(final ResultSet rs, int rowNum) throws SQLException { FC_Account account = new FC_Account(); account.id = rs.getInt(1); account.id_user_ = rs.getInt(2); account.date_create = rs.getDate(3); account.balance = rs.getBigDecimal(4); return account; } @Override public PreparedStatementCreator createInsert(final FC_Account account) { return new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement( "insert into FC_Account(" + "id_user_, balance)" + " values(?, ?)", RET_ID); ps.setInt(1, account.id_user_); ps.setBigDecimal(2, account.balance); return ps; } }; } @Override public PreparedStatementCreator createUpdate(final FC_Account entity) { return new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement( "update FC_Account set id_user_= ? " + ",balance = ? " + " where id = ? "); ps.setInt(1, entity.id_user_); ps.setBigDecimal(2, entity.balance); ps.setInt(3, entity.id); return ps; } }; } }