diff --git a/src/tutorialJava/capitulo8_Acceso_A_Datos/mysql/Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement.java b/src/tutorialJava/capitulo8_Acceso_A_Datos/mysql/Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement.java index aa803c3..e6cd673 100644 --- a/src/tutorialJava/capitulo8_Acceso_A_Datos/mysql/Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement.java +++ b/src/tutorialJava/capitulo8_Acceso_A_Datos/mysql/Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement.java @@ -52,6 +52,32 @@ public class Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement { } + + /** + * @throws SQLException + * + */ + private static void realizaSelect (Connection conn) throws SQLException { + + PreparedStatement ps = conn.prepareStatement( + "select * from tutorialjavacoches.concesionario " + + "where LOWER(localidad) = ? and LOWER(nombre) like ?"); + ps.setString(1, "lucena"); + ps.setString(2, "%hermanos%"); + + ResultSet rs = ps.executeQuery(); + + // Navegación del objeto ResultSet + while (rs.next()) { + System.out.println (rs.getInt("id") + " " + rs.getString ("cif")+ + " " + rs.getString("nombre") + " " + rs.getString("localidad")); + } + + rs.close(); + ps.close(); + } + + /** * @throws SQLException @@ -67,17 +93,6 @@ public class Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement { ps.setString(2, "111111B"); ps.setString(3, "Hermanos O'Bryan"); ps.setString(4, "Lucena"); - - - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); - java.util.Date fechaNac = null; - try { - fechaNac = sdf.parse("19/03/1977 15:33:00"); - } catch (ParseException e) { - e.printStackTrace(); - } - - ps.setDate(0, new java.sql.Date(fechaNac.getTime()) ); int filasAfectadas = ps.executeUpdate(); @@ -135,9 +150,10 @@ public class Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement { try { Connection conn = getConexion(); - realizaInsert(conn); + realizaSelect(conn); +// realizaInsert(conn); // realizaUpdate(conn, "Concesionario José María", "Lucena", 22); -// realizaDelete(conn, 23); +// realizaDelete(conn, 22); conn.close();