Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2006

    Red face Unanswered: Need help connecting to a Oracle DB

    Hi there, im very new to Oracle, and this forum :D , and a lil unsure how to do some stuffs.

    My situation is, im working on NetBeans and have to connect to a Oracle DB in Oracle Database 10g Express Edition. So far i did:

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.ResultSet;
    import java.sql.Statement;

    final private String driverName = "oracle.jdbc.driver.OracleDriver";

    Im not sure of this the connection string, is the syntax below correct?

    conn = DriverManager.getConnection("jdbc:oracle:thin:@ + dbmsHost + ":" + dbmsPortNumber + ":" dbmsName + userId + passWord);

    If so, is this how the connection string should look like? Example:
    conn = DriverManager.getConnection("jdbc:oracle:thin:@loc alhost:8081:HashTable,user,pass");

    Also in NetBeans, under Runtime, i've added Oracle driver. When trying to connect, they ask for this:

    May i know what is the SID? Is it the table name?

    Is there any other thing else i missed out? Do i need to set CLASSPATH in command prompt? Im unsure of what to set besides the "ojdbc14.jar" driver file.

    Any help will be appreciated. Been trying to connect for quite some time but i keep getting error msg :S Thanks for reading this.

  2. #2
    Join Date
    Jan 2004
    Croatia, Europe
    Provided Answers: 5
    I don't know anything about NetBeans, but, basically, connection to an Oracle database can be done using such a connect string:

    connect username/its_password@database

    Host, port and SID you are talking about can be found in the TNSNAMES.ORA file (I'm not sure you have it on your computer, but DBA should tell you those values).

    Entry in the TNSNAMES.ORA looks like this:
    ORA10G =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
        (CONNECT_DATA =
          (SERVICE_NAME = ora10g)
    Host, is this example, is "localhost", but can be any IP address or its alias (found in, if on MS Windows, the hosts file).

    Oracle database is *usually* installed using port 1521 (so, if you don't know it, you can always try 1521 - there are good chances you'll guess right).

    As a SID value, try using SERVICE_NAME (in this example, "ora10g") (as SID, system identifier was used.up to Oracle 8i. Since then, it is SERVICE_NAME).

    So, your jdbc:oracle:thin:@<HOST>:<PORT>:<SID> would then be something like


    As I've already said, I know nothing about things you are working with, but I hope some of this could help you.

  3. #3
    Join Date
    Aug 2004
    DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott", "tiger");
    The default SID with Oracle XE is "XE" and as Littlefoot said, 1521 is the default listener port, so provided you didn't change them after the install, just replace "scott" with your user and "tiger" with his password and it should work fine.

    There are many JDBC examples here on OTN (Oracle Technology Network).

    HTH & Regards,

    ORA-000TK : No bind variable detected... Shared Pool Alert code 5 - Nuclear query ready .

  4. #4
    Join Date
    Jul 2006
    Thanks for the quick response =D

    I manage to find the TNSNAMES.ORA file but they have 2-3 entries that look like the chunk Littlefoot posted.

    When i tried connecting jdbcracle:thin:@<HOST>:<PORT>:<SID> with the values i found, i keep getting "Invalid Oracle URL specified" error. I have tried all combinations but none worked.

    Hmm also, Littlefoot mention to use connection string:
    connect username/its_password@database

    how do i go about inputting this into my java file? Im writing it like that now (system being userName and Hash my table name):
    conn = DriverManager.getConnection("connect system/password@Hash");

    Doesn't look right to me though. tried just:
    connect system/password@Hash
    but it gave me an error.

    Also tried RBARAER's method of:
    conn = DriverManager.getConnection("jdbcracle:thin:@jdbcracle:thin:@localhost:1521:xe","system", "password");
    and other SIDs but all dont work either.

    I was told i need to add:
    Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();

    but it kept giving me error whereever i put it. I get <identifier>expected if i put after the declarations in my class.

    Lastly, i need to have these settings too right?

    Properties props = new Properties();
    props.setProperty("user", <user>);
    props.setProperty("password", <password>);
    String url = "jdbcracle:thin:@hostort:sid";

    Not too sure where to place them either

    Thanks once again
    Im so lost

  5. #5
    Join Date
    Jul 2006
    When i try to do it this way,

    Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();

    DriverManager.registerDriver(oracle.jdbc.driver.Or acleDriver());

    Properties props = new Properties();
    props.setProperty("user", system);
    props.setProperty("password", password);

    conn = DriverManager.getConnection("jdbc:oracle:thin:@jdb c:oracle:thin:@localhost:1521:ids","system", "password");

    the 1st line works, no error msg. But the following 4 lines gave me error:

    L2: package does not exist
    L3-5 (those property ones): cannot find symbol


  6. #6
    Join Date
    Jan 2004
    Croatia, Europe
    Provided Answers: 5
    Uh, no ...

    Post #3

    "conn = DriverManager.getConnection("connect system/password@Hash");"

    CONNECT works in SQL*Plus environment, such as
    SQL> connect scott/tiger@ora10
    I'm sorry, I was misunderstood.

    Post #4

    conn = DriverManager.getConnection("jdbc:oracle:thin:@jdb c:oracle:thin:@localhost:1521:ids","system", "password");

    Is the database installed on your PC? "Localhost" doesn't mean local in your LAN, but on your PC.

    If it is on your PC, and you've found TNSNAMES.ORA, it suggests that you have Oracle database available. So, can you connect to it through SQL*Plus? At the command prompt, type

    C:> sqlplus system/its_password@local_database

    What do you get? Success or failure? Perhaps it would be easier to find a winning username+password+database combination before trying to make those beans to work.

  7. #7
    Join Date
    Aug 2003
    Where the Surf Meets the Turf @Del Mar, CA
    Provided Answers: 1
    I suggest you follow the #1 Sticky Post in the forum by visiting & do a keyword search on JAVA JDBC.
    Tom has many fine coding example.
    Also you seem to be very weak WRT Oracle terminology.
    Visit and read the fine Concepts Manual.
    Google is your friend, but only if you use it!
    HTH & YMMV
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  8. #8
    Join Date
    Jul 2006
    Post #6:

    it's ok you dont have to apologize =)

    I understand that localhost means my own computer. I tried connecting to it using SQL*Plus and it worked. it shows:

    Connected to:
    Oracle Database 10g Express Edition Release - Production

    But when i tried connecting in NetBeans it gave me an error. I think it's because i didnt set the properties n stuffs correctly.

    Managed to solve the "<identifier> expected" error but still stuck with the "package don't exist" and "cannot find symbol" for the properties.

    I have to work in NB as this is suppose to be an application, it will work with the database when it is running.

    Post #7:

    Hi there, thanks for the advice, appreciated it =) Ya im very weak, first time coming in contact with Oracle and im assigned a project to work on which im not familiar with either. Been trying to familiarize myself with the overwhelming load of stuffs.
    Last edited by MentalSB; 07-04-06 at 23:29.

Posting Permissions

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