Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection cnn = null;
- String baseDatos = "jdbc:oracle:thin:@190.215.50.5:1433:orcl";
- String usuario = "seccion123", password = "seccion123";
- try{
- //Registrar driver
- Class.forName("oracle.jdbc.OracleDriver");
- //Conectar a la base de datos
- cnn = DriverManager.getConnection(baseDatos, usuario, password);
- if(cnn != null){
- Statement stm = cnn.createStatement();
- //ExecuteUpdate para insert, update y delete
- //stm.executeUpdate("insert into bryan (rut, nombre, carrera, edad) " +
- // "values('1-9','chasca dormido','ing',23)");
- ResultSet rstRegistros = stm.executeQuery("Select * from bryan order by nombre desc");
- String resultado = "";
- while(rstRegistros.next()){
- resultado = resultado + rstRegistros.getString("nombre") + ", edad : " + rstRegistros.getInt("edad") + "\n";
- }
- txtResultado.setText(resultado);
- }else{
- cnn.rollback();
- JOptionPane.showMessageDialog(null, "No hay conexión");
- }
- }catch(Exception ex){
- JOptionPane.showMessageDialog(null, "Error " + ex.toString());
- }finally{
- try {
- cnn.close();
- } catch (SQLException ex) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement