/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmProduct.java
 *
 * Created on Dec 21, 2013, 10:22:03 PM
 */

/**
 *
 * @author pooja
 */
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

public class frmProduct extends javax.swing.JFrame {

    /** Creates new form frmProduct */
    public frmProduct() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblImage = new javax.swing.JLabel();
        lblProdId = new javax.swing.JLabel();
        txtProdId = new javax.swing.JTextField();
        lblProdName = new javax.swing.JLabel();
        txtProdName = new javax.swing.JTextField();
        lblProdVersion = new javax.swing.JLabel();
        txtProdVers = new javax.swing.JTextField();
        lblProdPrice = new javax.swing.JLabel();
        txtProdPrice = new javax.swing.JTextField();
        lblProdValid = new javax.swing.JLabel();
        txtProdValid = new javax.swing.JTextField();
        btnSubmit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Product Information");

        lblImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/3.JPG"))); // NOI18N

        lblProdId.setText(" Product Id :");

        lblProdName.setText("Product Name :");

        lblProdVersion.setText("Product Version :");

        lblProdPrice.setText("Product Price :");

        lblProdValid.setText("Product Validity :");

        btnSubmit.setText("Submit");
        btnSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubmitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(lblImage, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(61, 61, 61)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblProdValid)
                    .addComponent(lblProdPrice)
                    .addComponent(lblProdId)
                    .addComponent(lblProdName)
                    .addComponent(lblProdVersion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtProdName, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtProdValid, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtProdPrice, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtProdVers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnSubmit)
                    .addComponent(txtProdId, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblProdId)
                    .addComponent(txtProdId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblProdName)
                    .addComponent(txtProdName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProdVers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblProdVersion))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProdPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblProdPrice))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblProdValid)
                    .addComponent(txtProdValid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38)
                .addComponent(btnSubmit))
            .addComponent(lblImage, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
        
                String url="jdbc:odbc:SPC";
		Connection con;
		Statement stmt;
                String sql;
	        sql="insert into db_accessadmin.tblProduct(ProductId,ProdName,ProdVersion,ProdPrice,ProdValidity) " +
                        "values('"+txtProdId.getText()+"','"+txtProdName.getText()+"','"+txtProdVers.getText()+"',"+
                        "'"+txtProdPrice.getText()+"','"+txtProdValid.getText()+"');";

		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch(ClassNotFoundException e)
		{
			System.err.print("ClassNotFoundException :");
			System.err.print(e.getMessage());
		}

		try
		{
			con=DriverManager.getConnection(url);
			stmt=con.createStatement();
			stmt.executeUpdate(sql);
			JOptionPane.showMessageDialog(null,"Record inserted successfully");
			stmt.close();
			con.close();

		}
		catch(SQLException ex)
		{

                    	JOptionPane.showMessageDialog(null,ex);
			JOptionPane.showMessageDialog(null,"Record not inserted!");
		}
    }//GEN-LAST:event_btnSubmitActionPerformed
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmProduct().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSubmit;
    private javax.swing.JLabel lblImage;
    private javax.swing.JLabel lblProdId;
    private javax.swing.JLabel lblProdName;
    private javax.swing.JLabel lblProdPrice;
    private javax.swing.JLabel lblProdValid;
    private javax.swing.JLabel lblProdVersion;
    private javax.swing.JTextField txtProdId;
    private javax.swing.JTextField txtProdName;
    private javax.swing.JTextField txtProdPrice;
    private javax.swing.JTextField txtProdValid;
    private javax.swing.JTextField txtProdVers;
    // End of variables declaration//GEN-END:variables


}
