leonelhl

Falabella-TestConnection-jt400

Oct 16th, 2019 (edited)
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.PreparedStatement;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5.  
  6. public class TestConnection {
  7.  
  8.     public static void main(String[] args) {
  9.         Connection dbConnection = null;
  10.         PreparedStatement preparedStatement = null;
  11.         String sql = "SELECT * FROM CURSO.ARCHIVO3";
  12.         try {
  13.             dbConnection = ConnectionManager.getConnection();
  14.             preparedStatement = dbConnection.prepareStatement(sql);
  15.             ResultSet rs = preparedStatement.executeQuery();
  16.             int cantidad = 0;
  17.             while (rs.next()) {
  18.                 cantidad++;
  19.                 System.out.println("RUT: " + rs.getString("RUT_CLI")+"-"+rs.getString("RUT_CLI"));
  20.                 System.out.println("NOMBRE: " + rs.getString("NOMBRE_CLI"));
  21.                 System.out.println("APELLIDO: " + rs.getString("APELLIDO_CLI"));
  22.                 System.out.println("DIRECCION: " + rs.getString("DIRECCION_CLI"));
  23.                 System.out.println("EMAIL: " + rs.getString("EMAIL_CLI"));
  24.                 System.out.println("----------------------------");
  25.             }
  26.            
  27.             System.out.println("Cantidad de registros: "+cantidad);
  28.         } catch (SQLException e) {
  29.             System.out.println(e.getMessage());
  30.         } finally {
  31.             if (preparedStatement != null) {
  32.                     try {
  33.                         preparedStatement.close();
  34.                     } catch (SQLException e) {
  35.                         System.out.println(e.getMessage());
  36.                     }
  37.             }
  38.             if (dbConnection != null) {
  39.                     try {
  40.                         dbConnection.close();
  41.                     } catch (SQLException e) {
  42.                         System.out.println(e.getMessage());
  43.                     }
  44.             }
  45.         }
  46.         System.out.println("Fin procesamiento");
  47.     }
  48. }
Add Comment
Please, Sign In to add comment