Your SlideShare is downloading. ×
0
Java Y Oracle
Java Y Oracle
Java Y Oracle
Java Y Oracle
Java Y Oracle
Java Y Oracle
Java Y Oracle
Java Y Oracle
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Java Y Oracle

4,890

Published on

Ejemplo sencillo para conectarse a oracle

Ejemplo sencillo para conectarse a oracle

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,890
On Slideshare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
90
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×