I am trying to connect my JSF application to my Oracle 11g database. A while back I had a JSF application connecting a similar way with a Derby database. Around the same time I was able to connect to an Oracle 11g database via a Java program I wrote.
I've tried to port the code into this recent project, and while everything looks correct, my connection in the code is returning null.
To further this issue, NetBeans seems to lock up when I try to debug. I'm assuming it goes to use the port that is running GlassFish 4, but somehow can't tell its occupied.
Any help is appreciated; please let me know if I can provide further information that I somehow overlooked.
Code snippets as follows:
@ManagedBean(name="OracleBean")
@RequestScoped
public class OracleBean {
private String driver = "oracle.jdbc.driver.OracleDriver";
private String url = "jdbc:oracle:thin:@localhost:8081:xe";
private String dbName = "test";
private String dbUsername = "Username";
private String dbPassword = "password";
private Connection connect = null;
private OracleMethods Method;
/**
* Creates a new instance of DataBean
*/
public OracleBean() {
driver = "oracle.jdbc.driver.OracleDriver";
url = "jdbc:oracle:thin:@localhost:8081:xe";
dbName = "Test";
dbUsername = "Username";
dbPassword = "password";
connect = null;
Method = new OracleMethods();
}
public String getColorData(String rowID, int col) {
connect = Method.getConnection(driver, url, dbName, dbUsername, dbPassword);
if (connect == null) {
return "SQL Error";
}
//end Bean code
public class OracleMethods extends JPanel {
private Connection connect = null;
public OracleMethods() {}
public Connection getConnection(String driver, String url, String dbName, String dbUsername, String dbPassword) {
try {
Class.forName(driver).newInstance();
connect = DriverManager.getConnection((url + dbName), dbUsername, dbPassword);
} catch (Exception lex) {
lex.printStackTrace();
}
return connect;
}
tnsnames.oraOracleBeanconstructor, not both. Also there are twoOracleDriverclasses in the jar, one inoracle.jdbcand one inoracle.jdbc.driver- I'm pretty sure you want the first one instead of the one you're using.