2933a606a391b89a1fd16a4caeb5b0ace686dfe4.svn-base 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.persistence.service.logic;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Timestamp;
  7. import java.util.Calendar;
  8. import org.apache.commons.logging.Log;
  9. import org.apache.commons.logging.LogFactory;
  10. import com.persistence.DbConnection;
  11. import com.persistence.service.exception.PersistenceException;
  12. import com.sysmodel.datamodel.xmlmodel.able.MdpDataSource;
  13. /**
  14. * sysmodel com.sysmodel.persistence create time 2006-5-26
  15. *
  16. * @author nbs
  17. */
  18. public class MysqlLogicHelper extends DefaultLogicHelper{
  19. private Log log = LogFactory.getLog(SQLServerLogicHelper.class);
  20. public Connection getConnection(MdpDataSource datasource) {
  21. Connection connection = super.getConnection(datasource);
  22. if (connection == null) {
  23. try {
  24. DbConnection dbConnection = new DbConnection();
  25. connection = dbConnection.getConnection(datasource);
  26. } catch (ClassNotFoundException e) {
  27. log.error(e);
  28. } catch (SQLException e) {
  29. log.error(e);
  30. }
  31. }
  32. return connection;
  33. }
  34. public String getDataBaseTime(Connection con) throws PersistenceException {
  35. String time = "";
  36. String sql = "select now() sysdate";
  37. try {
  38. PreparedStatement ps = con.prepareStatement(sql);
  39. ResultSet rs = ps.executeQuery();
  40. if (rs.next()) {
  41. Timestamp timesamp = rs.getTimestamp(1);
  42. if (timesamp != null) {
  43. Calendar calendar = Calendar.getInstance();
  44. calendar.setTimeInMillis(timesamp.getTime());
  45. java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(
  46. "yyyy-MM-dd HH:mm:ss");
  47. time = df.format(calendar.getTime());
  48. }
  49. }
  50. rs.close();
  51. ps.close();
  52. } catch (Exception e) {
  53. throw new PersistenceException(e.getMessage());
  54. }
  55. return time;
  56. }
  57. }