Advertisement
Guest User

PreparedStatement

a guest
Apr 27th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. private Connection conector;
  2. private Statement declaracion;
  3. private PreparedStatement declaracionPreparada; // NEW!
  4. private ResultSet lectura;
  5.  
  6.  
  7. public void conectarBD(){
  8.     try {
  9.         Class.forName("com.mysql.jdbc.Driver");
  10.         conector = DriverManager.getConnection("jdbc:mysql://localhost/bd_uno", "sa", "12345");
  11.        
  12.         catch ...
  13.        
  14. }
  15.  
  16. public boolean insertarProducto(){
  17.     String sql = "INSERT INTO producto (CODPROVEEDOR, NOMBRE, DESCRIPCION, PRECIO, DESCONTINUADO) VALUES (?, ?, ?, ?, ?);";    l
  18.     declaracionPreparada = conector.prepareStatement(sql);
  19.    
  20.     declaracionPreparada.setInt(1, this.codProveedor);
  21.     declaracionPreparada.setString(2, this.nombre);
  22.     declaracionPreparada.setString(3, this.descripcion);
  23.     declaracionPreparada.setInt(4, this.precio);
  24.     declaracionPreparada.setBoolean(5, this.descontinuado);
  25.    
  26.     declaracionPreparada.executeUpdate();
  27.    
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement