Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Borrar un registro, todos los registros o una tabla en una base de datos derby usando Java
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String dbName = "/DerbyDB/ExampleDB";
String connectionURL = "jdbc:derby:" + dbName;
Connection conn = null;
} catch(java.lang.ClassNotFoundException e) {
try {
conn = DriverManager.getConnection(connectionURL);
Statement st = conn.createStatement();
// borra un usuario en concreto
st.execute("DELETE * FROM users WHERE idUser='101'");
// borra todos los usuarios
st.execute("DELETE * FROM users");
// borra la tabla users
st.execute("DELETE TABLE users");
} catch (Throwable e) {
System.out.println("Ha fallado el borrado de datos");
} finally {
try { conn.close(); }
catch (Throwable t){}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment