Advertisement
Guest User

arocompaniero

a guest
Sep 23rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. static BufferedReader tec=new BufferedReader (new InputStreamReader(System.in));
  2.  
  3. public static void main(String[] args) {
  4. String jdbcUrl = "jdbc:mysql://localhost:3306/ciclismo" ;
  5.  
  6. Connection con = null;
  7. PreparedStatement pstmt = null;
  8. ResultSet rs = null;
  9.  
  10. String nomEquipo="ONCE";
  11.  
  12. try{
  13. con = DriverManager.getConnection(jdbcUrl, "root", "mysql");
  14.  
  15.  
  16.  
  17. //a
  18. //4 valores codigo, tipo, color, premio
  19. pstmt=con.prepareStatement("insert into maillot values(?,?,?,?)");
  20. //coger valor del campo 1 (codigo)
  21. String cod = tec.readLine();
  22. pstmt.setString(1, cod);
  23. //coger valor del campo 2 (tipo)
  24. String tipo = tec.readLine();
  25. pstmt.setString(2, tipo);
  26. //coger valor del campo 3 (color)
  27. String color = tec.readLine();
  28. pstmt.setString(3, color);
  29. //coger valor del campo 4 (premio)
  30. int premio = Integer.parseInt(tec.readLine());
  31. pstmt.setInt(4, premio);
  32.  
  33. pstmt.executeUpdate();
  34.  
  35. //b
  36. int edad [] = {20,25};
  37. String [] equipo = {"BANESTO", "ONCE"};
  38.  
  39. String sql = "select dorsal, nombre, from ciclista, where nomeq =? and year (current_date())-year(nacimiento)>?";
  40. pstmt = con.prepareStatement(sql);
  41.  
  42. int len = edad.length;
  43. for (int i = 0; i < len; i++) {
  44. pstmt.setString(1,equipo[i]);
  45. pstmt.setInt(2, edad[i]);
  46. rs = pstmt.executeQuery();
  47.  
  48. System.out.println("mayores de: "+edad[i]);
  49.  
  50. while(rs.next()){
  51. Integer dorsal = rs.getInt(1);
  52. String nom = rs.getString(2);
  53. System.out.println(equipo[i]+ " "+ nom+" - "+dorsal);
  54. }
  55. }
  56.  
  57.  
  58. } catch (Exception e) {
  59. // TODO Auto-generated catch block
  60. e.printStackTrace();
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement