Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Conexion {
- private static Connection cnx = null;
- public static Connection obtener() throws SQLException, ClassNotFoundException {
- if (cnx == null) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- cnx = DriverManager.getConnection("jdbc:mysql://localhost/deliverytrackingdb", "root", "root");
- } catch (SQLException ex) {
- System.out.println(ex.getMessage());
- } catch (ClassNotFoundException ex) {
- System.out.println(ex.getMessage());
- }
- }
- return cnx;
- }
- }
- public class Consulta {
- private final String tabla;
- private final Connection cnx;
- public Consulta(String tabla) throws SQLException, ClassNotFoundException{
- this.tabla = tabla;
- this.cnx = Conexion.obtener();
- }
- public ResultSet recuperarPorId(int id) throws SQLException {
- Pedido pedido = null;
- ResultSet rs = null;
- try{
- PreparedStatement consulta = cnx.prepareStatement("SELECT * FROM " + this.tabla + " WHERE Id = ?" );
- consulta.setInt(1, id);
- rs = consulta.executeQuery();
- }
- catch(SQLException ex){
- System.out.println(ex.getMessage());
- }
- return rs;
- }
- }
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Mostrar Mapa</title>
- <link href="css/mapa.css" rel="stylesheet" type="text/css"/>
- </head>
- <body>
- <div id="map">
- </div>
- <div id="botonesMapa">
- <form action="#">
- <a href="index.jsp">Volver a Inicio</a>
- </form>
- </div>
- <%
- int id = 12;
- Consulta cons = new Consulta("pedido");
- String dir = null;
- Pedido ped = null;
- ResultSet rs = null;
- try {
- rs = cons.recuperarPorId(id);
- if (rs.next())
- 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"));
- else
- System.out.println("No hay nada");
- dir = ped.getDireccion();
- } catch (Exception ex) {
- System.out.println(ex.getMessage());
- }
- %>
- <script src="js/jquery.js" type="text/javascript"></script>
- <script src="js/googleMap.js" type="text/javascript"></script>
- <script>
- geocoding('<%=dir%>');
- </script>
- <script src="https://maps.googleapis.com/maps/api/js?key=KEY&callback=initMap"
- async defer></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement