Advertisement
Guest User

Untitled

a guest
Nov 1st, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. public class Conexion {
  2.  
  3. private static Connection cnx = null;
  4.  
  5. public static Connection obtener() throws SQLException, ClassNotFoundException {
  6. if (cnx == null) {
  7. try {
  8. Class.forName("com.mysql.jdbc.Driver");
  9. cnx = DriverManager.getConnection("jdbc:mysql://localhost/deliverytrackingdb", "root", "root");
  10. } catch (SQLException ex) {
  11. System.out.println(ex.getMessage());
  12. } catch (ClassNotFoundException ex) {
  13. System.out.println(ex.getMessage());
  14. }
  15. }
  16. return cnx;
  17. }
  18. }
  19.  
  20. public class Consulta {
  21.  
  22. private final String tabla;
  23. private final Connection cnx;
  24.  
  25. public Consulta(String tabla) throws SQLException, ClassNotFoundException{
  26. this.tabla = tabla;
  27. this.cnx = Conexion.obtener();
  28. }
  29.  
  30. public ResultSet recuperarPorId(int id) throws SQLException {
  31. Pedido pedido = null;
  32. ResultSet rs = null;
  33. try{
  34. PreparedStatement consulta = cnx.prepareStatement("SELECT * FROM " + this.tabla + " WHERE Id = ?" );
  35. consulta.setInt(1, id);
  36. rs = consulta.executeQuery();
  37. }
  38. catch(SQLException ex){
  39. System.out.println(ex.getMessage());
  40. }
  41. return rs;
  42. }
  43. }
  44.  
  45. <html>
  46. <head>
  47. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  48. <title>Mostrar Mapa</title>
  49. <link href="css/mapa.css" rel="stylesheet" type="text/css"/>
  50. </head>
  51. <body>
  52. <div id="map">
  53. </div>
  54. <div id="botonesMapa">
  55. <form action="#">
  56. <a href="index.jsp">Volver a Inicio</a>
  57. </form>
  58. </div>
  59.  
  60. <%
  61. int id = 12;
  62. Consulta cons = new Consulta("pedido");
  63. String dir = null;
  64. Pedido ped = null;
  65. ResultSet rs = null;
  66. try {
  67. rs = cons.recuperarPorId(id);
  68. if (rs.next())
  69. ped = new Pedido(rs.getString("descripcion"), Integer.parseInt(rs.getString("precio")), rs.getString("direccion"), (rs.getString("fechaHora")), rs.getString("comentario"), rs.getString("idEstado"), rs.getString("idRepartidor"));
  70. else
  71. System.out.println("No hay nada");
  72. dir = ped.getDireccion();
  73. } catch (Exception ex) {
  74. System.out.println(ex.getMessage());
  75. }
  76. %>
  77.  
  78. <script src="js/jquery.js" type="text/javascript"></script>
  79. <script src="js/googleMap.js" type="text/javascript"></script>
  80. <script>
  81. geocoding('<%=dir%>');
  82. </script>
  83. <script src="https://maps.googleapis.com/maps/api/js?key=KEY&callback=initMap"
  84. async defer></script>
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement