Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package siddhesh;
- import java.sql.*;
- import javax.swing.JOptionPane;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- /**
- *
- * @author mca
- */
- public class rich2 extends javax.swing.JFrame {
- Connection c=null;
- PreparedStatement ps=null;
- private Component frame;
- /**
- * Creates new form rich2
- */
- public rich2() {
- 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">
- private void initComponents() {
- l1 = new javax.swing.JLabel();
- t1 = new javax.swing.JTextField();
- b1 = new javax.swing.JButton();
- b2 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- t2 = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- l1.setText("Product Name");
- b1.setText("Add");
- b1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- b1ActionPerformed(evt);
- }
- });
- b2.setText("Delete");
- b2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- b2ActionPerformed(evt);
- }
- });
- jLabel1.setText("Price");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(46, 46, 46)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(b1)
- .addComponent(l1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(95, 95, 95)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(b2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(t1)
- .addComponent(t2))
- .addContainerGap(129, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(41, 41, 41)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(l1)
- .addComponent(t1, 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.LEADING)
- .addComponent(jLabel1)
- .addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(33, 33, 33)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(b1)
- .addComponent(b2))
- .addContainerGap(145, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String s1=t1.getText();
- String s3=t2.getText();
- try{
- Class.forName("com.mysql.jdbc.Driver");
- c=DriverManager.getConnection("jdbc:mysql://localhost:3306/fattu","root","");
- String q="insert into akshay values (?,?)";
- ps=c.prepareStatement(q);
- ps.setString(1, s1);
- ps.setString(2, s3);
- ps.execute();
- c.close();
- JOptionPane.showMessageDialog(frame, "Data inserted");
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null,e);
- }
- }
- private void b2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String s2=t1.getText();
- try{
- Class.forName("com.mysql.jdbc.Driver");
- c=DriverManager.getConnection("jdbc:mysql://localhost:3306/fattu","root","");
- String q="delete from akshay where pname = ?";
- ps=c.prepareStatement(q);
- ps.setString(1, s2);
- ps.execute();
- c.close();
- JOptionPane.showMessageDialog(frame, "Data deleted");
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null,e);
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(rich2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(rich2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(rich2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(rich2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new rich2().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton b1;
- private javax.swing.JButton b2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel l1;
- private javax.swing.JTextField t1;
- private javax.swing.JTextField t2;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment