daily pastebin goal
14%
SHARE
TWEET

PreparedStatement

a guest Apr 27th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top