Guest User

Untitled

a guest
Oct 22nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. conexionBD cc = new conexionBD();
  2. Connection cn=cc.conectar;
  3. String sql="";
  4.  
  5. if(rbnHerraOfi.isSelected())
  6. tip=rbnHerraOfi.getText();
  7. else
  8. tip=rbnArtPape.getText();
  9. sql="INSERT INTO productos (Articulo,Precio_compra,Precio_venta,Stock_min,TipoArticulo,Cantidad) VALUES (?,?,?,?,?,?)";
  10.  
  11. try {
  12. PreparedStatement pst = cn.prepareStatement(sql);
  13. pst.setString(1,txt_NombrePro.getText());
  14. pst.setDouble(2,Double.parseDouble(txtPrecioCompraPro.getText()));
  15. pst.setDouble(3,Double.parseDouble(txtPrecioVentaPro.getText()));
  16. pst.setInt(4,Integer.parseInt(txtStockMinimo.getText()));
  17. pst.setString(5,tip);
  18. pst.setInt(6,Integer.parseInt(txtCantidadPro.getText()));
  19.  
  20. int n=pst.executeUpdate();
  21. if(n>=0){
  22. JOptionPane.showMessageDialog(null,"Registros Guardados con Exito");
  23. limpiar();
  24. }
  25.  
  26. } catch (SQLException ex) {
  27. JOptionPane.showMessageDialog(null,""+ex);
  28.  
  29. }
  30. `
  31.  
  32. public class conexionBD {
  33. Connection conectar=null;
  34.  
  35. public Connection conectar() {
  36.  
  37. try {
  38. Class.forName("org.gjt.mm.mysql.Driver");
  39. conectar=DriverManager.getConnection("jdbc:mysql://localhost/papeleria","root","");
  40. JOptionPane.showMessageDialog(null, "Conectado correctamente");
  41. } catch (Exception e) {
  42. JOptionPane.showMessageDialog(null, "Error al conectarse a la base de datos"+e);
  43. }
  44. return conectar;
  45. }
  46.  
  47. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  48. at pepeleria2.Admin2.btnGuardarProActionPerformed(Admin2.java:650)
  49.  
  50. if(rbnHerraOfi.isSelected()) {
  51. tip=rbnHerraOfi.getText();
  52. } else {
  53. tip=rbnArtPape.getText();
  54. sql="INSERT INTO productos (Articulo,Precio_compra,Precio_venta,Stock_min,TipoArticulo,Cantidad) VALUES (?,?,?,?,?,?)";
  55. }
Add Comment
Please, Sign In to add comment