Java Y Oracle

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Java Y Oracle - Presentation Transcript

    1. Java y Oracle
      • Vamos a Generar una aplicación para extraer informacion de la base de datos, utilizando java, la base de datos oracle 10g, NetBeans.
    2. Java y Oracle
      • Abrimos el netbeans
      • Nueva clase(Para hacer una aplicación de consola)
      • Importamos las librerias necesarias de acceso a datos:
          • import java.sql.DriverManager;
          • import java.sql.Connection;
          • import java.sql.Statement;
          • import java.sql.ResultSet;
          • import java.sql.Date;
          • import java.sql.SQLException;
    3. Java y Oracle
      • Dentro de main comenzamos a declarar la conexión:
      / / STEP 1:Declare a Connection Variable Connection conn = null; try{ / / STEP 2: Register JDBC driver String driver = "oracle.jdbc.driver.OracleDriver"; Class.forName(driver); //STEP 3: Open a connection System.out.println("Connecting to database..."); / / Print Connecting to Database String jdbcUrl = "jdbc:oracle:thin:@3.211.62.156:1521:orcl"; / / database host String user = "hr"; / / Database User String password = “tiger"; / / Database Password conn = DriverManager.getConnection(jdbcUrl,user,password); //STEP 4: Execute a query Statement stmt = conn.createStatement(); String sql; sql = "SELECT * from jobs"; / / Querie statement ResultSet rs = stmt.executeQuery(sql); / / Executing user
    4. Java y Oracle
      • Se imprimen los resultados
      //STEP 5: Printing the result while(rs.next()){ //Retrieve by column name String ssn= rs.getString(1); String name = rs.getString(2); System.out.println("Job ID: " + ssn); System.out.println(", Name: " + name); } //Se cierran las conexiones rs.close(); stmt.close(); conn.close(); }
    5. Java y Oracle
      • Bloque Catch
      • Para el caso de algun error, vamos a incluir el bloque catch
      catch(SQLException se){ //Handle errors for JDBC se.printStackTrace(); }catch(Exception e){ //Handle errors for Class.forName e.printStackTrace(); }finally{ //finally block used to close resources try{ if(conn!=null) conn.close(); } catch(SQLException se) { se.printStackTrace(); }//end finally try }//end try System.out.println(“Error, revisar codigo!!!"); }//end main }//end FirstQuery
    6. Java y Oracle
      • Ejecutando nuestro programa
    7. Java y Oracle
      • Fin
      • Preguntas: [email_address]
      • [email_address]
    8. Java y Oracle
      • Fin

    + plsqlagsplsqlags, 2 years ago

    custom

    757 views, 0 favs, 2 embeds more stats

    Ejemplo sencillo para conectarse a oracle

    More info about this presentation

    © All Rights Reserved

    • Total Views 757
      • 668 on SlideShare
      • 89 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 25
    Most viewed embeds
    • 87 views on http://plsqlags.blogspot.com
    • 2 views on http://74.125.47.132

    more

    All embeds
    • 87 views on http://plsqlags.blogspot.com
    • 2 views on http://74.125.47.132

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags