Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1.         Connection cnn = null;
  2.         String baseDatos = "jdbc:oracle:thin:@190.215.50.5:1433:orcl";
  3.         String usuario = "seccion123", password = "seccion123";
  4.         try{
  5.             //Registrar driver
  6.             Class.forName("oracle.jdbc.OracleDriver");
  7.             //Conectar a la base de datos
  8.             cnn = DriverManager.getConnection(baseDatos, usuario, password);
  9.             if(cnn != null){
  10.                 Statement stm = cnn.createStatement();
  11.                 //ExecuteUpdate para insert, update y delete
  12.                 //stm.executeUpdate("insert into bryan (rut, nombre, carrera, edad) " +
  13.                 //        "values('1-9','chasca dormido','ing',23)");  
  14.                
  15.                 ResultSet rstRegistros = stm.executeQuery("Select * from bryan order by nombre desc");
  16.                 String resultado = "";
  17.                
  18.                 while(rstRegistros.next()){
  19.                     resultado = resultado + rstRegistros.getString("nombre") + ", edad : " + rstRegistros.getInt("edad") + "\n";
  20.                 }
  21.                 txtResultado.setText(resultado);
  22.             }else{
  23.                 cnn.rollback();
  24.                 JOptionPane.showMessageDialog(null, "No hay conexión");
  25.             }
  26.         }catch(Exception ex){
  27.             JOptionPane.showMessageDialog(null, "Error " + ex.toString());
  28.         }finally{
  29.             try {        
  30.                 cnn.close();
  31.             } catch (SQLException ex) {}
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement