Results 1 to 8 of 8
  1. #1
    ahmadian is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default connect to oracle from java

    Hi,

    I am tring to connect to oracle via java code,
    I want to use a connection to oracle so i can build a database or use an already build database.

    the thing is:
    1- i don't know how to build a database with a table in oracle
    2- i tried to get a connection with the following code:

    try
    {
    java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    conn = java.sql.DriverManager.getConnection("jdbc:oracle: thin:@localhost","ahmadian","pouya");
    System.out.println("Connected to database!");
    }
    catch (java.sql.SQLException ex)
    {
    javax.swing.JOptionPane.showMessageDialog
    (null,ex,"pouya: Failed to connect with database",javax.swing.JOptionPane.ERROR_MESSAGE);
    }


    but i get an error saying:
    Java.sqlSQLException.listener refused the connection with the following error: ORA-12514, TNS: listener dose not currently know of service requested in connect descriptor
    the connection descriptor used by the client was: local host


    3- could some one answer me this: if you want to connect to oracle via NetBeans and you don't know anything about oracle what should you do, step by step with complete description neede for a 6 years old!!

    I would be really thankful if any one can answer me.

    Pouya.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by ahmadian View Post
    Java.sqlSQLException.listener refused the connection with the following error: ORA-12514, TNS: listener dose not currently know of service requested in connect descriptor
    the connection descriptor used by the client was: local host
    Fairly self descriptive. It's looking for an Oracle database called localhost, which it can't find. Have you got Oracle up and running somewhere that you're trying to connect to?

    Quote Originally Posted by ahmadian View Post
    3- could some one answer me this: if you want to connect to oracle via NetBeans and you don't know anything about oracle what should you do, step by step with complete description neede for a 6 years old!!

    I would be really thankful if any one can answer me.

    Pouya.
    No idea, I'm afraid. Oracle do reasonable walkthroughs, so they may have one.

  3. #3
    ahmadian is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default

    Hi,

    Thank you so much for your reply, i was completely hopeless until your hint helped me.
    Now I got a new error as fallow:

    java.SQLException: Io exception: The Network Adapteer could not establish the connection.


    any more hints? hopefully?!

    pouya.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by ahmadian View Post
    Hi,

    Thank you so much for your reply, i was completely hopeless until your hint helped me.
    Now I got a new error as fallow:

    java.SQLException: Io exception: The Network Adapteer could not establish the connection.


    any more hints? hopefully?!

    pouya.
    Still looks like the connection is wrong somewhere. Either the name you're giving, or the port, or the db server isn't up and running. Something along those lines. Try and SQL*Plus onto the db, or tnsping it, from the box your Java is running on.

  5. #5
    ak88 is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Default

    You better try to use dsn and then try whether it is working or not
    I think it will give a better solution

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    First, are you sure you have an Oracle database running on your local system? You can get Oracle from their Web site and install it. Second, you have to create a database, tables, etc., before you can connect to it.

  7. #7
    Muntasir is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default Re: connect to oracle from java

    package DBM;

    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.lang.ClassNotFoundException;

    public class OracleJDBC {

    public static void main(String[] argv) {

    System.out.println("-------- Oracle JDBC Connection Testing ------");

    try {

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

    } catch (ClassNotFoundException e) {

    System.out.println("Where is your Oracle JDBC Driver?");
    e.printStackTrace();
    return;

    }

    System.out.println("Oracle JDBC Driver Registered!");

    Connection connection = null;

    try {

    connection = DriverManager.getConnection("jdbc:oracle:thin:@XYZ .asiapacific.hpqcorp.net:1521:orcl", "Username","password");

    } catch (SQLException e) {

    System.out.println("Connection Failed! Check output console");
    e.printStackTrace();
    return;

    }

    if (connection != null) {
    System.out.println("You made it, take control your database now!");
    } else {
    System.out.println("Failed to make connection!");
    }
    }

    }

  8. #8
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: connect to oracle from java

    @Muntasir, please don'r resurrect a 4 year old post. Thread locked.

Similar Threads

  1. oracle JDBC java
    By silia_motor in forum JDBC
    Replies: 4
    Last Post: 05-10-2009, 10:37 AM
  2. Replies: 0
    Last Post: 08-27-2008, 10:27 AM
  3. Java + Sybase + Oracle
    By xxAlemanxx in forum Advanced Java
    Replies: 1
    Last Post: 06-26-2008, 08:41 AM
  4. Using JDBC to connect to ORACLE database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 12:27 PM
  5. Making connect 4 in java
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:10 AM

Posting Permissions

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