java - DAO factory pattern createConnection from datasource -


DAO factory pattern is referring to this article,

I have CloudscapeDAOFactory , There is a connection to making a public static connection () method. I'm using DriverManager.registerDriver () and DriverManager.getConnection () to create a connection.

  // DriverManager.registerDriver (new OracleDriver ()); // conn = DriverManager.getConnection (CONNECTION_URL);  

Individual DAO classes such as CloudscapeCustomerDAO [example 9.4] Call CloudscapeDAOFactory.createConnection () to get connection as needed. Public class CloudscapeCustomerDAO applies Customer DAO {Public CloudscapeCustomerDAO () {// initialization} // Methods in Class // Using CloudscapeDAOFactory.createConnection () // Getting the Connection Required

Question: Now I am enforcing connection pooling and my problem ' static Keeping the keyword 'in the createConnection () in CloudscapeDAOFactory

CloudscapeDAOFactory.java

Private Data Source Datasource; Private fixed connection conn = null; Public Zero SetDataSource (Datasource Data Source) {this.dataSource = DataSource; } Public static connection buildsConnection () throws SQLException {conn = dataSource.getConnection () // Wrong static reference // timing compilation / // If I remove 'static' then CloudscapeCustomerDAO is an example of CloudscapeDAOFactory call this method need to! // If I'm planning to keep 'stable', then I need to declare datasource as a stable, which I think is wrong. }

Springconfig.xml

  & lt; Bean id = "spring data source" class = "org.apache.commons.dbcp .asicDataSource" destroy-method = "close" & gt; & Lt; Property name = "url" value = "jdbc: oracle: thin: @localhost: 1521: SPRING_UNNI" /> & Lt; Property Name = "driverClassName" value = "oracle.jdbc.driver.OracleDriver" /> & Lt; Property Name = "User Name" Value = "Anani" /> & Lt; Property Name = "Password" Value = "Anani" /> & Lt; Property Name = "Deleted Deleted" value = "Correct" /> & Lt; Property name = "initial size" value = "20" /> & Lt; Property Name = "Maxactive" value = "30" /> & Lt; / Bean & gt; & Lt; Bean id = "Cloudscape doprintik" class = "com.myapp.dao.CloudscapeDAOFactory" & gt; & Lt; Property Name = "Data Source" Riff = "Vertical Data Source" /> & Lt; / Bean & gt;  

Update: JDBCTemplate can also be used to call the stored procedure Reference: This question can be used by calling JDBCTemplate Not to be.

update2: Incompatible with this thread, but keeping a note:

Note: There was a problem while trying for connection: Error: TNS: Currently connected descriptor I do not know about the given SID

    

  & lt; Property Name = "url" value = "jdbc: oracle: thin: @localhost: 1521 / SPRING_UNNI" />  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -