Skip to content

Instantly share code, notes, and snippets.

@rchavarria
Created December 10, 2012 12:19
Show Gist options
  • Save rchavarria/4250253 to your computer and use it in GitHub Desktop.
Save rchavarria/4250253 to your computer and use it in GitHub Desktop.
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;
try{
Class.forName(driver);
} catch(java.lang.ClassNotFoundException e) {
e.printStackTrace();
}
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");
e.printStackTrace();
} 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