Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class TestConnection {
- public static void main(String[] args) {
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- String sql = "SELECT * FROM CURSO.ARCHIVO3";
- try {
- dbConnection = ConnectionManager.getConnection();
- preparedStatement = dbConnection.prepareStatement(sql);
- ResultSet rs = preparedStatement.executeQuery();
- int cantidad = 0;
- while (rs.next()) {
- cantidad++;
- System.out.println("RUT: " + rs.getString("RUT_CLI")+"-"+rs.getString("RUT_CLI"));
- System.out.println("NOMBRE: " + rs.getString("NOMBRE_CLI"));
- System.out.println("APELLIDO: " + rs.getString("APELLIDO_CLI"));
- System.out.println("DIRECCION: " + rs.getString("DIRECCION_CLI"));
- System.out.println("EMAIL: " + rs.getString("EMAIL_CLI"));
- System.out.println("----------------------------");
- }
- System.out.println("Cantidad de registros: "+cantidad);
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- try {
- preparedStatement.close();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- if (dbConnection != null) {
- try {
- dbConnection.close();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- }
- System.out.println("Fin procesamiento");
- }
- }
Add Comment
Please, Sign In to add comment