Ejercicio Internacional Preguntas
Ejercicio Internacional Preguntas
/*
*/
package modelo;
import java.sql.ResultSet;
import java.util.HashMap;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.table.DefaultTableModel;
/**
/**
* @author User
*/
public Marca(){
this.id = id;
this.marca = marca;
}
public int getId() {
return id;
this.id = id;
return marca;
this.marca = marca;
try{
cn.abrirConexion();
tabla.setColumnIdentifiers(encabezado);
while(consulta.next()){
datos[0] = consulta.getString("id");
datos[1] = consulta.getString("marcas");
tabla.addRow(datos);
cn.cerrarConexion();
} catch(SQLException ex){
System.out.println(ex.getMessage());
return tabla;
try{
PreparedStatement parametro;
cn = new Conexion();
cn.abrirConexion();
parametro = (PreparedStatement)cn.conexionBD.prepareStatement(query);
parametro.setString(1, getMarca());
retorno = parametro.executeUpdate();
cn.cerrarConexion();
}catch(SQLException ex){
System.out.println(ex.getMessage());
retorno = 0;
return retorno;
}
try{
PreparedStatement parametro;
cn = new Conexion();
cn.abrirConexion();
parametro = (PreparedStatement)cn.conexionBD.prepareStatement(query);
parametro.setString(1, getMarca());
parametro.setInt(2, getId());
retorno = parametro.executeUpdate();
cn.cerrarConexion();
}catch(SQLException ex){
System.out.println(ex.getMessage());
retorno = 0;
return retorno;
try{
PreparedStatement parametro;
cn = new Conexion();
cn.abrirConexion();
parametro = (PreparedStatement)cn.conexionBD.prepareStatement(query);
parametro.setInt(1, getId());
retorno = parametro.executeUpdate();
cn.cerrarConexion();
}catch(SQLException ex){
System.out.println(ex.getMessage());
retorno = 0;
return retorno;
CONTROLADOR sr_marca
/*
*/
package controlador;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import modelo.Marca;
/**
* @author User
*/
/**
* methods.
*/
Marca marca;
response.setContentType("text/html;charset=UTF-8");
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet sr_marca</title>");
out.println("</head>");
out.println("<body>");
if (marca.agregar() > 0) {
response.sendRedirect("index.jsp");
}else{
if("modificar".equals(request.getParameter("btn_modificar"))){
if (marca.modificar() > 0) {
response.sendRedirect("index.jsp");
}else{
if("eliminar".equals(request.getParameter("btn_eliminar"))){
if (marca.eliminar() > 0) {
response.sendRedirect("index.jsp");
}else{
}
}
out.println("</body>");
out.println("</html>");
/**
*/
@Override
processRequest(request, response);
/**
*/
@Override
processRequest(request, response);
/**
*/
@Override
}// </editor-fold>
Index
<!DOCTYPE html>
<html>
<head>
<title>Marcas</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
</head>
<body>
<h1><center>Formulario Marcas</center></h1>
<div class="container">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<center>
<br>
<label for="lbl_id"><b>ID</b></label>
<br>
<br>
</form>
</div>
</div>
</div>
</div>
</div>
<thead>
<tr>
<th>Marcas</th>
</tr>
</thead>
<tbody id="tbl_marcas">
<center>
<%
tabla = marca.leer();
out.println("<td>"+tabla.getValueAt(t, 1)+"</td>");
out.println("</tr>");
%>
</center>
</tbody>
</table>
</center>
</center>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
var id = target.data('id');
$("#txt_id").val(id);
$("#txt_marca").val(marca);
$("#modal_marcas").modal('show');
});
</script>
</body>
</html>
Conexión
*/
package modelo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.*;
/**
* @author User
*/
Connection conexionBD;
try{
Class.forName(jdbc);
try{
this.conexionBD.close();
}catch(SQLException e){
JOptionPane.showMessageDialog(null, "Error " + e.getMessage());
Puertos
Funcionamiento