Home » Developer & Programmer » JDeveloper, Java & XML » Connecting Java bean to Oracle?
Connecting Java bean to Oracle? [message #187423] Sun, 13 August 2006 22:52 Go to next message
FremenWar
Messages: 1
Registered: August 2006
Junior Member
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
Re: Connecting Java bean to Oracle? [message #187481 is a reply to message #187423] Mon, 14 August 2006 03:30 Go to previous message
orafaqer
Messages: 48
Registered: July 2006
Member
Of course your method won't work until you change driver/url/user/pass.
Look here.
Second method is more acceptable due to usage of JNDI services.
The role of JNDI in J2EE
HTH.
Previous Topic: xml parsing failed,, xdk is installed
Next Topic: Calling webservices in forms
Goto Forum:
  


Current Time: Mon Nov 25 00:46:43 CST 2024