Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- conexionBD cc = new conexionBD();
- Connection cn=cc.conectar;
- String sql="";
- if(rbnHerraOfi.isSelected())
- tip=rbnHerraOfi.getText();
- else
- tip=rbnArtPape.getText();
- sql="INSERT INTO productos (Articulo,Precio_compra,Precio_venta,Stock_min,TipoArticulo,Cantidad) VALUES (?,?,?,?,?,?)";
- try {
- PreparedStatement pst = cn.prepareStatement(sql);
- pst.setString(1,txt_NombrePro.getText());
- pst.setDouble(2,Double.parseDouble(txtPrecioCompraPro.getText()));
- pst.setDouble(3,Double.parseDouble(txtPrecioVentaPro.getText()));
- pst.setInt(4,Integer.parseInt(txtStockMinimo.getText()));
- pst.setString(5,tip);
- pst.setInt(6,Integer.parseInt(txtCantidadPro.getText()));
- int n=pst.executeUpdate();
- if(n>=0){
- JOptionPane.showMessageDialog(null,"Registros Guardados con Exito");
- limpiar();
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null,""+ex);
- }
- `
- public class conexionBD {
- Connection conectar=null;
- public Connection conectar() {
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- conectar=DriverManager.getConnection("jdbc:mysql://localhost/papeleria","root","");
- JOptionPane.showMessageDialog(null, "Conectado correctamente");
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Error al conectarse a la base de datos"+e);
- }
- return conectar;
- }
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- at pepeleria2.Admin2.btnGuardarProActionPerformed(Admin2.java:650)
- if(rbnHerraOfi.isSelected()) {
- tip=rbnHerraOfi.getText();
- } else {
- tip=rbnArtPape.getText();
- sql="INSERT INTO productos (Articulo,Precio_compra,Precio_venta,Stock_min,TipoArticulo,Cantidad) VALUES (?,?,?,?,?,?)";
- }
Add Comment
Please, Sign In to add comment