1 25 29 package org.jresearch.gossip.dao; 30 31 import java.sql.Connection ; 32 import java.sql.PreparedStatement ; 33 import java.sql.ResultSet ; 34 import java.sql.SQLException ; 35 import java.util.Date ; 36 37 import javax.sql.DataSource ; 38 39 import org.jresearch.gossip.dao.drivers.DbDriver; 40 41 46 public abstract class DAO { 47 protected DataSource dataSource; 48 49 54 public DataSource getDataSource() { 55 return dataSource; 56 } 57 58 63 public void setDataSource(DataSource source) { 64 if (this.dataSource == null) { 65 dataSource = source; 66 } 67 } 68 69 77 public Date now() throws SQLException { 78 Connection connection = this.dataSource.getConnection(); 79 PreparedStatement st = connection.prepareStatement(DbDriver 80 .getInstance().getQueries().getSql_NOW()); 81 ResultSet rs = null; 82 Date now = null; 83 84 try { 85 rs = st.executeQuery(); 86 87 if (rs.next()) { 88 now = rs.getTimestamp(1); 89 } 90 } finally { 91 if (rs != null) { 92 rs.close(); 93 } 94 95 st.close(); 96 connection.close(); 97 } 98 99 return now; 100 } 101 } 102 | Popular Tags |