Hello all.
I am trying to get an instance of my OracleConnection from the class OracleConnection.
The compiled class is in the same folder as the Emp class that I am trying to compile. The Emp.java class cannot recognize the OracleConnection class. I have tried to add it to my classpath with no sucess, I have tried to import the class and I have also tried to create the package with both files in the package. I figure I am doing something really stupid.
OracleConnection class
import java.sql.*;
import java.util.*;
public class OracleConnection{
private
String dbURL = "";
private String dbUsername = "";
private String dbPassword = "";
private PropertyResourceBundle properties;
private final static String KEY_CONNPOOL_PROPERTIES = "connection.properties";
private final static String ANUM_DATASOURCE_URL = "myMainDatabase.datasource.url";
private final static String ANUM_DATASOURCE_USERNAME = "myMainDatabase.datasource.username";
private final static String ANUM_DATASOURCE_PASSWORD = "myMainDatabase.datasource.password";
public static OracleConnection theInstance = null;
public OracleConnection(){
}
public OracleConnection getInstance(){
if(theInstance == null)
initialize();
return theInstance;
}
/**
* intialize the instance variables.
*/
private void initialize(){
theInstance = new OracleConnection();
properties = (PropertyResourceBundle)ResourceBundle.getBundle(KEY_CONNPOOL_PROPERTIES);
dbURL = properties.getString(ANUM_DATASOURCE_URL);
dbUsername = properties.getString(ANUM_DATASOURCE_USERNAME);
dbPassword = properties.getString(ANUM_DATASOURCE_PASSWORD);
}
/**
* This method is used to get the connection to the
* ACode database.
*
* @return Connection, the connection to the ACode database.
* @exception SQLException
* exception is throw when unable to get the connection
* to the database
*/
protected synchronized Connection getConnection()throws SQLException{
return DriverManager.getConnection(dbURL, dbUsername, dbPassword);
}
protected void releaseConnection(Connection connection) throws SQLException{
connection.close();
}
}
Emp class as it stands now.
import java.sql.*;
import java.util.*;
public connectionManager = OracleConnection.getInstance;
public class Emp{
private String empNo = "";
private String eName = "";
public Emp(OracleConnection connectionManager, String empNo){
this.connectionManager = connectionManager;
this.empNo = empNo;
setEmployeeName();
}
/**
* WRITE THE ACCESSORY METHODS TO GET empName AND empId;
*/
public String getEmployeeName(){
return this.eName;
}
public String getEmployeeId(){
return this.empNo;
}
private void setEmployeeName(){
Connection connection = null;
try{
connection = connectionManager.getConnection();
PreparedStatement stmt = connection.preparedStatement("Select eName from Emp where empNo = ?");
stmt.setString(1, getEmployeeId());
ResultSet result = stmt.executeQuery();
while(result.next()){
this.eName = result.getString(1);
}
result.close();
stmt.close();
connectionManager.releaseConnection();
}catch(SQLException e){
connectionManager.releaseConnection();
e.printStackTrace();
}
}
}
Thanks in advance for any advice.
Roger
[ October 04, 2002: Message edited by: Roger Garner ]