Está en la página 1de 10

I.

- OBJETIVOS:
 Instalar y configurar los componentes necesarios para programar en Java (Windows 10).
 Crear, compilar, ejecutar y depurar programas de Java.

II.- SEGURIDAD:
Advertencia:
En este laboratorio está prohibida la manipulación del
hardware, conexiones eléctricas o de red; así como la
ingestión de alimentos o bebidas.

III.- FUNDAMENTO TEÓRICO:


Revise sus diapositivas del tema antes del desarrollo del laboratorio.

IV.- NORMAS EMPLEADAS:


No aplica

V.- RECURSOS:
 En este laboratorio cada alumno trabará con un equipo con Windows 10.
 La instalación del software requerido se realizará en un equipo Virtual

VI.- METODOLOGÍA PARA EL DESARROLLO DE LA TAREA:


 El desarrollo del laboratorio es individual.

VII.- PROCEDIMIENTO:

Aplicación 1: Procesar los datos del ResultSet

ResultSet Results;
String nombre;
String apellidos;
String printrow;
boolean records=Results.next();
if (!records){
System.out.println("No hay datos");
return;
} else {
do {
nombre=Results.getString(nombre);
apellidos=Results.getString(apellidos);
printrow=nombre + “ “ + apellidos;
System.out.println(printrow);
} while (Results.next());
}
Aplicación 2: Utilizar el objeto Statement para ejecutar una consulta

String url=" jdbc:oracle:thin:@localhost:1521:ORCL";


String userID="hr";
String password="hr"
Statement DataRequest;
ResultSet Results;
Connection Db;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Db=DriverManager.getConnection(url,userID, password );
}
catch(ClassNotFoundException error){
System.err.println("No se puede cargar el controlador JDBC " + error);
System.exit(1);
}
catch(SQLException error){
System.err.println("No se puede conectar con la BD " + error);
System.exit(2);
}
try {
String query="SELECT * FROM CLIENTES";
DataRequest=Db.createStatement();
Results =DataRequest.executeQuery(query);
// Aquí va el código que interactúa con el ResultSet
DataRequest.close();
}
catch(SQLException error){
System.err.println("SQL error" + error);
System.exit(3);
}
Db.close();

Aplicación 3: Uso del método executeUpdate()

String url=" jdbc:oracle:thin:@localhost:1521:ORCL";


String userID="hr";
String password="hr"
Statement DataRequest;
Connection Db;
int rowsUpdated;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Db=DriverManager.getConnection(url,userID, password );
}
catch(ClassNotFoundException error){
System.err.println("No se puede cargar el controlador JDBC " + error);
System.exit(1);
}
catch(SQLException error){
System.err.println("No se puede conectar con la BD " + error);
System.exit(2);
}
try {
String query="UPDATED Clientes SET alm_codigo='A' WHERE Precio='1000' ";
DataRequest=Db.createStatement();
rowsUpdated=DataRequest.executeUpdate(query);
DataRequest.close();
}
catch(SQLException error){
System.err.println("SQL error" + error);
System.exit(3);
}
Aplicación 4: Actualizar el ResultSet
String url=" jdbc:oracle:thin:@localhost:1521:ORCL";
String userID="hr";
String password="hr"
Statement DataRequest;
ResultSet Results;
Connection Db;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Db=DriverManager.getConnection(url,userID, password );
}
catch(ClassNotFoundException error){
System.err.println("No se puede cargar el controlador JDBC " + error);
System.exit(1);
}
catch(SQLException error){
System.err.println("No se puede conectar con la BD " + error);
System.exit(2);
}
try {
String query="SELECT nombre, apellido FROM Clientes WHERE nombre='Juan' AND apellido='Diaz'";
DataRequest=Db.createStatement(ResultSet.CONCUR_UPDATABLE);
Results=DataRequest.executeQuery(query);
}
catch(SQLException error){
System.err.println("Error de SQL" + error);
System.exit(3);
}
boolean records=Results.next();
if(!records){
System.out.println("No hay datos");
System.exit(4);
}
try {
Results.updateString("apellido", "perez");
Results.updateRow();
DataRequest.close();
}
catch(SQLException error){
System.err.println("Error al mostrar los datos" + error);
System.exit(5);
}

Aplicación 5: Leer los datos de un ResultSet

String url=" jdbc:oracle:thin:@localhost:1521:ORCL";


String userID="hr";
String password="hr"
String printrow;
String nombre;
String apellido;
Statement DataRequest;
ResultSet Results;
Connection Db;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Db=DriverManager.getConnection(url,userID, password );
}
catch(ClassNotFoundException error){
System.err.println("No se puede cargar el controlador JDBC " + error);
System.exit(1);
}
catch(SQLException error){
System.err.println("No se puede conectar con la BD " + error);
System.exit(2);
}
try {
String query="SELECT nombre, apellido FROM Clientes";
DataRequest=Db.createStatement();
Results=DataRequest.executeQuery(query);
}
catch(SQLException error){
System.err.println("SQL error" + error);
System.exit(3);
}
boolean records=Results.next();
if(!records){
System.out.println("No hay datos");
System.exit(4);
}
try {
do{
nombre=Results.getString(1);
apellido=Results.getString(2);
printrow=nombre + " "+apellido;
System.out.println(printrow);
}while(Results.next());
DataRequest.close();
}
catch(SQLException error){
System.err.println("Error al mostrar los datos" + error);
System.exit(5);
}

EJERCICIOS

Oracle y/o Mysql

 Elabore una tabla Alumnos tanto en Oracle como en Mysql


 La estructura de Alumnos:
o Codigo (Entero)
o Apellidos (Texto)
o Nombres (Texto)
o DNI (Texto)
o Direccion (Texto)
Java

 Registre alumnos
 Mostrar alumnos
 Realizar una búsqueda de alumnos por DNI
OBSERVACIONES:

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________
__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

CONCLUSIONES:
__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

__________________________________________________________________________________________

"Dime y lo olvido, enséñame y lo recuerdo, involúcrame y lo aprendo”. Benjamín Franklin (1706-1790)

También podría gustarte