package com.persistence.service.logic; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Calendar; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.persistence.DbConnection; import com.persistence.service.exception.PersistenceException; import com.sysmodel.datamodel.xmlmodel.able.MdpDataSource; /** * sysmodel com.sysmodel.persistence create time 2006-5-26 * * @author nbs */ public class MysqlLogicHelper extends DefaultLogicHelper{ private Log log = LogFactory.getLog(SQLServerLogicHelper.class); public Connection getConnection(MdpDataSource datasource) { Connection connection = super.getConnection(datasource); if (connection == null) { try { DbConnection dbConnection = new DbConnection(); connection = dbConnection.getConnection(datasource); } catch (ClassNotFoundException e) { log.error(e); } catch (SQLException e) { log.error(e); } } return connection; } public String getDataBaseTime(Connection con) throws PersistenceException { String time = ""; String sql = "select now() sysdate"; try { PreparedStatement ps = con.prepareStatement(sql); ResultSet rs = ps.executeQuery(); if (rs.next()) { Timestamp timesamp = rs.getTimestamp(1); if (timesamp != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timesamp.getTime()); java.text.SimpleDateFormat df = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); time = df.format(calendar.getTime()); } } rs.close(); ps.close(); } catch (Exception e) { throw new PersistenceException(e.getMessage()); } return time; } }