
package ejerciciojdbc2;

import java.sql.Connection;
// import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Properties;

public class EjercicioJDBC2 {

    public static void main(String[] args) {
        try {
              Properties propertiesConexion = new Properties();
              propertiesConexion.put("user", "root");
              propertiesConexion.put("password", "");
              propertiesConexion.put("charSet", "ISO-8859-1");            
              //    CONEXION MySQL
              // Class.forName("com.mysql.jdbc.Driver");
              // Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/biblioteca", propertiesConexion);  
              com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver();
              Connection connection = driver.connect("jdbc:mysql://localhost:3306/biblioteca", propertiesConexion);             
/*     
              Properties propertiesConexion = new Properties();
              propertiesConexion.put("user", "scott");
              propertiesConexion.put("password", "tiger");
              propertiesConexion.put("charSet", "ISO-8859-1"); 
              //    CONEXION Oracle
              // Class.forName("oracle.jdbc.driver.OracleDriver");
              // Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", propertiesConexion);  
              oracle.jdbc.driver.OracleDriver driver = new oracle.jdbc.driver.OracleDriver();
              Connection connection = driver.connect("jdbc:oracle:thin:@localhost:1521:ORCL", propertiesConexion); 
*/                      
              String sql = "SELECT * FROM libros";
              Statement statement = connection.createStatement();
              ResultSet resultSet = statement.executeQuery(sql);
              while (resultSet.next()) {
                  System.out.println("id_libro :       " + resultSet.getString(1));
                  System.out.println("título :         " + resultSet.getString(2));
                  System.out.println("género :         " + resultSet.getString(3));
                  System.out.println("fecha edición :  " + new SimpleDateFormat("yyyy-MM-dd").format(resultSet.getDate(4)));
                  System.out.println("numero páginas : " + resultSet.getInt(5));
                  System.out.println("premiado:        " + resultSet.getInt(6));
                  System.out.println("--------------------------------------------------");
              }    
              connection.close();
         } catch(Exception e){
            e.printStackTrace();           
         }     
    }   
}
