Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbapp;
- import java.sql.*; // importa a class
- import java.util.Scanner;
- public class DBApp {
- public static void main(String[] args) throws SQLException {
- Connection conexao = DriverManager.getConnection(
- "jdbc:oracle:thin:@//camburi.pucrs.br:1521/facin11g",
- "bd104668", "bd104668");
- System.out.println("Conectado.");
- ResultSet rs;
- PreparedStatement stmt;
- String sql1 = "select palestra.titulo, p.nome, esc.NOMEESCOLA from palestra palestra inner join palestrante p on palestra.CODPALESTRANTE = p.CODPALESTRANTE inner join escola esc on palestra.CODESCOLA = esc.CODESCOLA";
- String sql2 = "SELECT esc.nomeescola as Nome_Escola, COUNT(pa.codpalestra) as Quantidade_palestras FROM escola esc LEFT JOIN palestra pa ON esc.CODESCOLA = pa.CODESCOLA GROUP BY esc.NOMEESCOLA order by 2 desc";
- String sql3 = "select nome, email from (select * from palestrante where idade >= 16)";
- String sql4 = "delete from aluno where codaluno = any(select CODALUNO from aluno where CODALUNO not in (select CODALUNO from participacao))";
- stmt = conexao.prepareStatement(sql1);
- rs = stmt.executeQuery();
- while (rs.next()){
- String titulo = rs.getString("titulo");
- String nome = rs.getString("nome");
- String escola = rs.getString("nomeescola");
- System.out.println("Titulo da palestra: " + titulo + " || Nome do Palestrante: " + nome + " || Nome da Escola: " + escola);
- }
- System.out.println("---");
- stmt = conexao.prepareStatement(sql2);
- rs = stmt.executeQuery();
- while (rs.next()){
- String escola = rs.getString("nome_escola");
- Integer quantidade = rs.getInt("quantidade_palestras");
- System.out.println("Nome da Escola: " + escola + " || Quantidade de palestras: " + quantidade);
- }
- System.out.println("---");
- stmt = conexao.prepareStatement(sql3);
- rs = stmt.executeQuery();
- while (rs.next()){
- String nome = rs.getString("nome");
- String email = rs.getString("email");
- if (email == null) {
- email = "não possui email";
- }
- System.out.println("Nome: " + nome + " || Email: " + email);
- }
- System.out.println("---");
- stmt = conexao.prepareStatement(sql4);
- stmt.execute();
- System.out.println("Alunos que não participaram de palestras removidos.");
- stmt.close();
- rs.close();
- conexao.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement