Last active
August 29, 2015 13:57
-
-
Save erickcg/9800184 to your computer and use it in GitHub Desktop.
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
//creando conexion | |
Class.forName("com.mysql.jdbc.Driver"); | |
Connection conexion = DriverManager.getConnection ("jdbc:mysql://localhost/prueba","root", "la_clave"); | |
//creando el vehiculo para ejecutar el query | |
Statement db = conexion.createStatement(); | |
// ejecutar query guardando el resultado en un ResultSet | |
ResultSet result = db.executeQuery ("select * from ------"); | |
// se usa executequery para unicamente el SELECT, para lo demas es executeupdate | |
ResultSet result = db.executeUpdate ("Update, Delete etcetc"); | |
//rs.next() mueve el contador al primer nodo y lo sigue haciendo hasta que sea null | |
while (rs.next()) | |
{ | |
// imprime el resultado por columnas, especificando int o string | |
System.out.println (result.getInt (1) + " " + result.getString (2)+ " " + result.getDate(3)); | |
} | |
//hasta al ultimo hay que cerrar la conexion a la db | |
conexion.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment