Created
December 10, 2012 12:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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