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:
@@ -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
|
* @throws SQLException
|
||||||
@@ -67,17 +93,6 @@ public class Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement {
|
|||||||
ps.setString(2, "111111B");
|
ps.setString(2, "111111B");
|
||||||
ps.setString(3, "Hermanos O'Bryan");
|
ps.setString(3, "Hermanos O'Bryan");
|
||||||
ps.setString(4, "Lucena");
|
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();
|
int filasAfectadas = ps.executeUpdate();
|
||||||
|
|
||||||
@@ -135,9 +150,10 @@ public class Ejemplo03_EjemplosInsertUpdateyDeleteConPreparedStatement {
|
|||||||
try {
|
try {
|
||||||
Connection conn = getConexion();
|
Connection conn = getConexion();
|
||||||
|
|
||||||
realizaInsert(conn);
|
realizaSelect(conn);
|
||||||
|
// realizaInsert(conn);
|
||||||
// realizaUpdate(conn, "Concesionario José María", "Lucena", 22);
|
// realizaUpdate(conn, "Concesionario José María", "Lucena", 22);
|
||||||
// realizaDelete(conn, 23);
|
// realizaDelete(conn, 22);
|
||||||
|
|
||||||
conn.close();
|
conn.close();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user