General discussion

  • Creator
    Topic
  • #2192162

    java & oracle

    Locked

    by sudeep.nigam ·

    how to connect java with oracle database

All Comments

  • Author
    Replies
    • #3142393

      Reply To: java & oracle

      by rleepnmcom ·

      In reply to java & oracle

      Try starting here:
      http://www.orafaq.com/faqjdbc.htm
      — RL

    • #3142267

      Reply To: java & oracle

      by kadsoft ·

      In reply to java & oracle

      import java.sql.*;

      public class MyConnection {

      /**
      * You need the oracle’s driver jar (classes12.jar)
      */
      public static void main(String args[]) {
      try {
      //Attempts to establish a connection to the given database URL.
      //The DriverManager attempts to select an appropriate driver from
      //the set of registered JDBC drivers.
      Class.forName(“oracle.jdbc.driver.OracleDriver”);
      Connection myConn = DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:MYDATABASE”, “user”, “password”);

      //Creates a Statement object for sending
      //SQL statements to the database.
      Statement myStatement = myConn.createStatement();

      //Executes the given SQL statement, which returns a single ResultSet object.
      ResultSet myResultSet = myStatement.executeQuery(“SELECT * FROM table”);

      //Iterates the resultSet so you can get the info
      while (myResultSet.next()) {
      System.out.println(myResultSet.getString(“column_table1”));
      }
      //close the ResultSet object
      myResultSet.close();

      //Releases this Connection object’s database and JDBC resources
      //immediately instead of waiting for them to be automatically released.
      myConn.close();
      }
      catch (ClassNotFoundException cnfex) {
      System.err.println(“Can’t load JDBC”);
      cnfex.printStackTrace();
      System.exit(1);
      }
      catch (SQLException sqlex) {
      System.err.println(“No connection”);
      sqlex.printStackTrace();
      }
      }

      }

    • #3203189

      Reply To: java & oracle

      by rajesh_m_vaghela ·

      In reply to java & oracle

      put oracle\ora92\lib\classes12.jar in your java application classpath. then load JDBC Driver
      Class.formName(“oracle.jdbc.OracleDriver”);

      user below url to connect database
      url = jdbc:oracle:thin:@Hostname:Portnumber:Databasename
      Connection c = DriverManager.getConnect(url).

      I think this is enough

Viewing 2 reply threads