Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uns.ConexionConsolaJavaDerby;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import uns.ConexionDB.Conexion;
- public class ConexionConsolaJavaDerby {
- static Connection connection = null;
- static Statement statement = null;
- static ResultSet resutSet = null;
- public static void main(String[] args) throws SQLException {
- //Obtenemos la conexion a Derby
- connection = Conexion.getConexion();
- String consulta = "SELECT * FROM estudiantes";
- //Preparamos la consulta
- statement = connection.createStatement();
- //Ejecutamos la consulta
- resutSet = statement.executeQuery(consulta);
- System.out.println("CÓDIGO\tNOMBRES\tAPELL\tEDAD\tSALARIO\tESTADO");
- //Recorremos el Resultset
- while (resutSet.next()) {
- int id,calificacion;
- String nombre, apellido;
- //Recogemos los datos llamando al nombre de la columna
- //que el Resultset nos devuelve
- id = resultSet.getInt("id");
- nombre = resultSet.getString("nombre");
- apellido = resultSet.getString("apellido");
- calificacion = resultSet.getInt("calificacion");
- //Imprimimos datos por consola
- System.out.println(id + "\t" + nombre + "\t" + apellido + " \t" + calificacion);
- }
- //Cerramos los elementos que se utilizaron
- resultSet.close();
- resultSet = null;
- statement.close();
- statement= null;
- connection.close();
- connection=null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement