SHOW:
|
|
- or go back to the newest paste.
1 | package uns.ConexionConsolaJavaDerby; | |
2 | ||
3 | import java.sql.Connection; | |
4 | import java.sql.ResultSet; | |
5 | import java.sql.SQLException; | |
6 | import java.sql.Statement; | |
7 | import uns.ConexionDB.Conexion; | |
8 | ||
9 | public class ConexionConsolaJavaDerby { | |
10 | static Connection connection = null; | |
11 | static Statement statement = null; | |
12 | static ResultSet resutSet = null; | |
13 | ||
14 | public static void main(String[] args) throws SQLException { | |
15 | //Obtenemos la conexion a Derby | |
16 | connection = Conexion.getConexion(); | |
17 | String consulta = "SELECT * FROM estudiantes"; | |
18 | //Preparamos la consulta | |
19 | statement = connection.createStatement(); | |
20 | //Ejecutamos la consulta | |
21 | resutSet = statement.executeQuery(consulta); | |
22 | ||
23 | System.out.println("CÓDIGO\tNOMBRES\tAPELL\tEDAD\tSALARIO\tESTADO"); | |
24 | ||
25 | //Recorremos el Resultset | |
26 | while (resutSet.next()) { | |
27 | int id,calificacion; | |
28 | String nombre, apellido; | |
29 | ||
30 | //Recogemos los datos llamando al nombre de la columna | |
31 | //que el Resultset nos devuelve | |
32 | id = resultSet.getInt("id"); | |
33 | nombre = resultSet.getString("nombre"); | |
34 | apellido = resultSet.getString("apellido"); | |
35 | calificacion = resultSet.getInt("calificacion"); | |
36 | ||
37 | //Imprimimos datos por consola | |
38 | System.out.println(id + "\t" + nombre + "\t" + apellido + " \t" + calificacion); | |
39 | } | |
40 | //Cerramos los elementos que se utilizaron | |
41 | resultSet.close(); | |
42 | resultSet = null; | |
43 | statement.close(); | |
44 | statement= null; | |
45 | connection.close(); | |
46 | connection=null; | |
47 | } | |
48 | } |