Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. public class Controlador_boton_insertar implements ActionListener {
  2.  
  3. public Conexion connect;
  4.  
  5. public PreparedStatement stmt1=null;
  6.  
  7. public Frame ventana;
  8.  
  9.  
  10. public Controlador_boton_insertar(Frame ventana)
  11. {
  12.  
  13. }
  14.  
  15. private void Controlador_boton_insertar() {
  16. // TODO Auto-generated method stub
  17.  
  18. connect= new Conexion();
  19.  
  20. Connection connect = null;
  21.  
  22. String consultainsertarfila= "INSERT INTO frutas(nombre, precio, fecha_vencimiento, origen, provincia) VALUES(?,?,?,?,?)";
  23.  
  24.  
  25. try{
  26.  
  27.  
  28.  
  29. Class.forName("org.gjt.mm.mysql.Driver");
  30.  
  31. connect= DriverManager.getConnection("jdbc:mysql://localhost:3306/productos", "root", "");
  32.  
  33. PreparedStatement stmt1 = connect.prepareStatement(consultainsertarfila);
  34.  
  35. stmt1.setString(1, this.ventana.camponombre.getText()); //acá es donde me vuelvo loco, si lo reemplazo por cualquier "andabien"
  36.  
  37. stmt1.setString(2, this.ventana.campoprecio.getText());
  38.  
  39. stmt1.setString(3, this.ventana.campovencimiento.getText());
  40.  
  41. stmt1.setString(4, this.ventana.campoorigen.getText());
  42.  
  43. stmt1.setString(5, this.ventana.campoprovincia.getText());
  44.  
  45. stmt1.executeUpdate();
  46.  
  47.  
  48. }
  49. catch(Exception e1)
  50. {
  51. e1.printStackTrace();
  52. }
  53.  
  54. }
  55.  
  56. @Override
  57. public void actionPerformed(ActionEvent e)
  58. {
  59. Controlador_boton_insertar();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement