I was working on a project and was using portSQL as my database but now I need to convert to Oracle.
Can someone tell me if I can still use the same connection method that I have that works for postgress or do I have to use a particular connection for Oracle.
The one I have is
public void MakeConnection()throws ClassNotFoundException, FileNotFoundException, IOException, SQLException
{
String url = "jdbc:postgresql:postgres";
String usr = "postgres";
String pwd = "dune";
// Load the driver
Class.forName("org.postgresql.Driver");
// Connect to database
System.out.println("Connecting to Database URL = " + url);
db = DriverManager.getConnection(url, usr, pwd);
System.out.println("Connected...Now creating a statement");
st = db.createStatement();
}
And the one people that I know when they use oracle use something like this
public websiteDAO() throws SQLException, NamingException
{
Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("jdbc/myDatabase");
con = ds.getConnection();
System.out.println("DB Connected");
loginUser = con.prepareStatement("select username,password1 FROM USERS");
}
I would imagine that I could just use my own and just change the URL, username, password and driver class to the one needed for oracle.
Can someone please tell if my method would work, as I won't have access to Oracle for a few weeks to test it myself and I really need to know now.
Thanks