Results 1 to 4 of 4

Thread: Help connecting

  1. #1
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default Help connecting

    I've just been assigned a new project where I'm writing java code to interact with my oracle database and I'm pretty lost. I have oracle 10gXE installed as my database and I'm using Eclipse for all my coding. I have this example code that works but when I try to supply the URL of my database I get problems and I'm not sure if it's because I'm not typing it in correctly or if I don't have something set up or what. Here's the code
    Java Code:
    public class JDBC_Test {
    
    	public static void main(String[] args) throws Exception {
    		
    	    OracleDataSource ods = new OracleDataSource();
    	    ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
    	    Connection conn = ods.getConnection();
    
    	    // Create Oracle DatabaseMetaData object
    	    DatabaseMetaData meta = conn.getMetaData();
    
    	    // gets driver info:
    	    System.out.println("JDBC driver version is " + meta.getDriverVersion());
    
               //JDBC driver version is 10.2.0.1.0XE is the output after running this
            }
    }
    I tried changing the setURL line to
    http://127.0.0.1:8080/apex
    which is the URL I use to access the login screen but it returns invalid oracle URL specified.

    Am I using the wrong URL or is something wrong in my code or what? I really have no idea where to even look to fix it.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    The documentation for the driver will tell you the exact format but it will be something like
    Java Code:
    Class.forName("org.oracle.jdbc.Driver");
    ods.getConnection("jdbc:oracle://localhost:1521/XE", username, password);
    if XE is the name of your database and org.oracle.jdbc.Driver is the name of the driver class
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    The example provided actually worked, I just had to unlock the HR account within the database.

    I guess I'm just a little confused as to what everything stands for. I'm assuming by using user/password@localhost will only work because I have the database installed on my harddrive. If I wanted to connect to one not on my network would the @localHost be changed to @"some ip address" ?

    the 1521 is the access port and I'm pretty sure that remains the same and XE is the name of the database(which I'm assuming can also be customized just not with this free database) correct?

    As for the jdbc:oracle:thin how does this function? I know the thin means use a thin layer connection so if I changed that to ftp all the @localHost stuff would be changed to an FTP location? What about jdbc and oracle?
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Changing to the style I presented would probably make it easier to understand, as it uses standard URI syntax - protocol://host:port/path

    Here the protocol is that provided by the database driver, the thin version of oracle's jdbc protocol.
    The host is the machine the server is on, localhost or db.example.org, etc.
    The port gives the port to connect to on the host to find the database server - 1521 apparently for yours
    Then the path will be the name of your database
    You then provide your username and password in separate arguments

    You can't use FTP to connect to a database, you have to use some kind of database driver - a jdbc driver if you're using Java, which you are.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. Connecting c with java
    By khajalid in forum Networking
    Replies: 6
    Last Post: 12-10-2008, 09:35 PM
  2. Connecting c with java
    By khajalid in forum Advanced Java
    Replies: 4
    Last Post: 09-11-2008, 04:47 AM
  3. Connecting to a Web server
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 07:57 PM
  4. Connecting to a database
    By peiceonly in forum New To Java
    Replies: 2
    Last Post: 04-06-2008, 02:28 PM
  5. Connecting to DB from Applet
    By ibanez270dx in forum New To Java
    Replies: 1
    Last Post: 11-13-2007, 11:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •