This is my data source, it is used as an attribute by every bean that has to talk to the database.
It is still not clear to me why a simple piece of 'classic'* jdbc code connects and the fancy spring does not.
Code:
package cms.data.db.oracle;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author jf
*/
public class OracleDataSource implements DataSource {
private final Log logger = LogFactory.getLog(this.getClass());
private String url = null;
private String driver = null;
private String username = null;
private String password = null;
public void setUsername(String username){
this.username = username;
}
public String getUsername(){
return this.username;
}
public String getPassword(){
return this.password;
}
public void setPassword(String password){
this.password = password;
}
public void setUrl(String url){
this.url = url;
}
public String getUrl(){
return this.url;
}
public void setDriver(String driver){
this.driver = driver;
}
public String getDriver(){
return this.driver;
}
/** Creates a new instance of OracleDataSource */
public OracleDataSource() {
}
public Connection getConnection() throws SQLException {
Connection result = null;
try {
Class.forName(getDriver());
}
catch (ClassNotFoundException cnfe){
logger.error(cnfe);
}
result = DriverManager.getConnection(getUrl(), getUsername(), getPassword());
return result;
}
public Connection getConnection(String username, String password) throws SQLException {
this.username = username;
this.password = password;
return getConnection();
}
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException {
throw new RuntimeException("not implemented");
}
public int getLoginTimeout() throws java.sql.SQLException {
throw new RuntimeException("not implemented");
}
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException {
throw new RuntimeException("not implemented");
}
public void setLoginTimeout(int seconds) throws java.sql.SQLException {
throw new RuntimeException("not implemented");
}
}
Cheers
Joachim
* classic =
Code:
...
url = System.getProperty("DB_URL");
db_driver = System.getProperty("DB_DRIVER");
Class.forName(db_driver);
conn = DriverManager.getConnection(url,username,password);
...