Está en la página 1de 6

1 /*

2 REALIZAR EL PROGRAMA QUE MUESTRE EN PANTALLA LAS TABLAS ALUMNO, CURSO Y PROFESOR DE LA BAS
3 PARA CADA TABLA Y AL PIE DEL REPORTE DE ALUMNOS IMPRIMIR LA CANTIDAD DE APROBADOS Y DESAPR
4 ESTA EN EL NIMBUS EN SEMANA 12
5 */
6 package basededatos2;
7 import java.sql.*;
8 import javax.swing.*;
9
10
11 public class Principal {
12
13
14
15
public static void main(String[]
(String[] args) {
16
String codigo,apellido,codigocurso,codigoprof;
17
Double prom;
18
19
int ca=0,cd=0;
20
try
21
{
22
Class.forName("com.mysql.jdbc.Driver");
Class.
("com.mysql.jdbc.Driver");
23
Connection conexion = DriverManager.getConnection(""+"jdbc:mysql://localhost/u
DriverManager.
(""+"jdbc:mysql://localhost/u
24
Statement instruccion = conexion.createStatement();
25
ResultSet tabla = instruccion.executeQuery("SELECT *FROM alumno");
26
System.out.println("
System.
.println("
Listado de Alumnos
");
27
System.out.println("................................................");
System.
.println("................................................");
28
System.out.println("Codigo
System.
.println("Codigo\tApellido\tCurso\tProfesor\tPromedio");
.println("Codigo
Promedio");
29
System.out.println("................................................");
System.
.println("................................................");
30
while(tabla.next())
31
{
32
System.out.println(tabla.getString(1)+
System.
.println(tabla.getString(1)+ "\t"
" " + tabla.getString(2)+ "
33
"\t"
"
" + tabla.getDouble(5));
34
if(tabla.getDouble(5)>=11.5)
35
ca++;
36
else
37
cd++;
38
}
39
System.out.println("................................................");
System.
.println("................................................");
40
System.out.println("Cantidad
System.
.println("Cantidad de aprobados"+ca);
41
System.out.println("Cantidad
System.
.println("Cantidad de desaprobados"+cd);
42
}
43
catch(ClassNotFoundException e)
44
{
45
System.out.println(e);
System.
.println(e);
46
}
47
catch(SQLException e)
48
{
49
System.out.println(e);
System.
.println(e);
50
}
52
53
54
55
56

catch(Exception e)
{
System.out.println(e);
System.
.println(e);
}

CURSO Y PROFESOR DE LA BASE DE DATOS UNIVERSIDAD POR MEDIO DE UN REPORTE


TIDAD DE APROBADOS Y DESAPROBADOS.ARCHIVO AGREGARLO EN BIBLIOTECAS, TRAERLO PARA EL EXAMEN

"+"jdbc:mysql://localhost/universidad 3","root","");

*FROM alumno");
umnos
");
.................");
Promedio");
.................");

abla.getString(2)+ "\t"
" " + tabla.getString(3)+"\t"
tabla.getString(3)+" " + tabla.getString(4)+

.................");

56
57
58
59
60
61 //Insertar datos en la tabla alumno ingresando desde teclado
62 try
63 {
64 Class.forName("com.mysql.jdbc.Driver");
("com.mysql.jdbc.Driver");
65 Connection conexion = DriverManager.getConnection("jdbc:"+"mysql://localhost/universidad
DriverManager.
("jdbc:"+"mysql://localhost/universidad 3
66 Statement instruction = conexion.createStatement();
67 cd=JOptionPane.
cd=JOptionPane.showConfirmDialog(null,"Desea
(null,"Desea aadir registro","Java-MySQL",JOptionPane.
68 if(cd==JOptionPane.
if(cd==JOptionPane.YES_OPTION)
69 {
70 codigo=JOptionPane.
codigo=JOptionPane.showInputDialog("Ingrese
("Ingrese codigo del"+"alumno");
71 apellido=JOptionPane.
apellido=JOptionPane.showInputDialog("Ingrese
("Ingrese apellidos"+"y nombre del alumno");
72 codigocurso=JOptionPane.
codigocurso=JOptionPane.showInputDialog("Ingrese
("Ingrese codigo del"+"curso");
73 codigoprof=JOptionPane.
codigoprof=JOptionPane.showInputDialog("Ingrese
("Ingrese codigo del"+"profesor");
74 prom=Double.
prom=Double.parseDouble(JOptionPane.
(JOptionPane.showInputDialog("Ingrese
(JOptionPane.
("Ingrese promedio del"+"curso"));
75 ResultSet f = instruction.executeQuery("SELECT * FROM alumno");
76 while(f.next())

instruccion.executeUpdate("INSERT
("INSERT INTO alumno (codalum,apellnom,codcur,codprof,prom) VALUE
,'"+ prom +"')');
79 }
80 }
81 catch(ClassNotFoundException e)
82 {
83 System.out.println(e);
.println(e);
84 }
85 catch(SQLException e)
86 {
87 System.out.println(e);
.println(e);
88 }
catch(Exception e)
90 {
91 System.out.println(e);
.println(e);
92 }
93 System.out.print("\n");
94 System.out.print("\n");
95 }
96 }

97
98
99
100
101

l://localhost/universidad 3","root","");

Java-MySQL",JOptionPane.YES_NO_OPTION);
Java-MySQL",JOptionPane.

bre del alumno");

omedio del"+"curso"));

,codcur,codprof,prom) VALUES ('"+codigo+"','"+apellido+"','"+codigocurso+"','"+codigoprof+"'

También podría gustarte