mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
kk
This commit is contained in:
@@ -53,6 +53,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
|
||||
*
|
||||
@@ -68,17 +94,6 @@ public class Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement {
|
||||
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();
|
||||
|
||||
System.out.println("Filas afectadas: " + filasAfectadas);
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user