Guest User

Untitled

a guest
Apr 9th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. import java.sql.*;
  2. import static javax.swing.UIManager.getString;
  3.  
  4. public class Conectora {
  5.  
  6. public static String nome;
  7.  
  8. public static void main(String[] args){
  9.  
  10. try {
  11. Statement atestamento;
  12. ResultSet resultado;
  13.  
  14. String usuario = "postgres";
  15. String senha = "123";
  16. String endereco = "jdbc:postgresql://localhost:5433/ueer5";
  17.  
  18. Class.forName("org.postgresql.Driver");
  19.  
  20. Connection con = DriverManager.getConnection(endereco, usuario, senha);
  21.  
  22. atestamento = con.createStatement();
  23.  
  24. atestamento.executeQuery("SELECT * FROM alunos WHERE codigo = 1;");
  25.  
  26. resultado = atestamento.getResultSet();
  27.  
  28. while (resultado.next()) {
  29.  
  30. nome = resultado.getString(2);
  31. }
  32.  
  33. System.out.println(nome);//fora do while
  34.  
  35. con.close();
  36.  
  37. System.out.println("Conexão bem-sucedida.");
  38.  
  39. } catch (Exception e){
  40. System.out.println("Conexão mal-sucedida.n"+e);
  41. }
  42.  
  43. System.out.println(nome);//fora do try-catch
  44. }
  45.  
  46. }
  47.  
  48. import com.itextpdf.text.Document;
  49. import com.itextpdf.text.Element;
  50. import com.itextpdf.text.Paragraph;
  51. import com.itextpdf.text.Font;
  52. import com.itextpdf.text.pdf.PdfWriter;
  53. import com.itextpdf.text.PageSize;
  54. import Gertrudes.Conectora;
  55. import static Gertrudes.Conectora.*;
  56. import java.awt.Desktop;
  57. import java.io.File;
  58. import java.io.FileOutputStream;
  59. import java.io.IOException;
  60. import java.util.Date;
  61. import java.util.logging.Level;
  62. import java.util.logging.Logger;
  63.  
  64. public class Declaradora {
  65.  
  66. public static void main(String[] args){
  67.  
  68. String aluno = null;
  69. String serie = "1º";
  70. String nascimento = "20/01/2001";
  71. String mae = "Beltrana de Tal";
  72. String pai = "Cicrano de Tal";
  73. String diretor = "Dirceu E. Torquato";
  74.  
  75. Document dec = new Document(PageSize.A4);
  76.  
  77. try{
  78. PdfWriter.getInstance(dec, new FileOutputStream("dec.pdf"));
  79.  
  80. dec.open();
  81. Paragraph titulo = new Paragraph("DECLARAÇÃO");
  82. titulo.setAlignment(1);
  83. titulo.setSpacingAfter(30);
  84. dec.add(titulo);
  85.  
  86. Paragraph texto = new Paragraph("Declaro para os fins que se fizerem necessários que o (a) aluno (a) "+ aluno +" está matriculado (a) e cursando regularmente o "+ serie +" ano do Ensino Fundamental neste estabelecimento de ensino no ano corrente.");
  87. texto.setAlignment(3);
  88. texto.setSpacingAfter(30);
  89. dec.add(texto);
  90.  
  91. Paragraph dados = new Paragraph("Data de nascimento: "+ nascimento +"nMãe: "+ mae +"nPai:"+ pai );
  92. //dados.setAlignment(Element.ALIGN_LEFT);
  93. dados.setSpacingAfter(30);
  94. dec.add(dados);
  95.  
  96. Paragraph assinatura = new Paragraph("____________________________n" + diretor + "nDiretor");
  97. assinatura.setAlignment(1);
  98. assinatura.setSpacingAfter(30);
  99. dec.add(assinatura);
  100.  
  101. Paragraph local = new Paragraph("Agricolândia - PI, "+ new Date());
  102. local.setAlignment(2);
  103. //assinatura.setSpacingAfter(30);
  104. dec.add(local);
  105.  
  106. dec.close();
  107.  
  108. } catch (Exception e){
  109. e.printStackTrace();
  110. }
  111.  
  112. try {
  113. Desktop.getDesktop().open(new File("dec.pdf"));
  114. } catch (IOException ex) {
  115. System.out.println("Errooouu!"+ ex);
  116. }
  117. System.out.println("nome: "+nome+"naluno: "+aluno);
  118. }
  119. }
Add Comment
Please, Sign In to add comment