How to store JComboBox item into database

Ads
 

How to store JComboBox item into database

import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JOptionPane; import javax.swing.JPanel;

/* import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import javax.swing.JOptionPane;*/

@SuppressWarnings("serial") public class ItemDetails extends javax.swing.JFrame {

String ID;

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JButton SaveBTN;
private javax.swing.JButton BackBTN;
private javax.swing.JTextField ItemcodeTF;
private javax.swing.JTextField TypeTF;
private javax.swing.JTextField ItemnameTF;
private javax.swing.JTextField DescriptionTF;
private javax.swing.JTextField ManufaturerTF;
private javax.swing.JTextField CostTF;

// End of variables declaration//GEN-END:variables /* public ItemDetails() { initComponents(); }*/

public ItemDetails(String id) {

    ID= id;
    initComponents();


    // TODO Auto-generated constructor stub
}

private void initComponents(){

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    ItemcodeTF = new javax.swing.JTextField();
    TypeTF = new javax.swing.JTextField();
    ItemnameTF = new javax.swing.JTextField();
    DescriptionTF = new javax.swing.JTextField();
    ManufaturerTF = new javax.swing.JTextField();
    CostTF = new javax.swing.JTextField();
    SaveBTN = new javax.swing.JButton();
    BackBTN = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("DETAIL FORM");

    setResizable(false);
    getContentPane().setLayout(new AbsoluteLayout());

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36));
    jLabel1.setForeground(new java.awt.Color(153, 0, 153));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("ADD NEW ITEMS");
    getContentPane().add(jLabel1,new AbsoluteConstraints(100, 20, -1, -1));

    jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
    jLabel2.setForeground(new java.awt.Color(153, 0, 153));
    jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel2.setText("Item Code");
    getContentPane().add(jLabel2,new AbsoluteConstraints(27, 140, 100, 20));

    jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
    jLabel3.setForeground(new java.awt.Color(153, 0, 153));
    jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel3.setText("Item Name");
    getContentPane().add(jLabel3,new AbsoluteConstraints(27, 180, 100, 30));


    jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
    jLabel4.setForeground(new java.awt.Color(153, 0, 153));
    jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel4.setText("Description");
    getContentPane().add(jLabel4,new AbsoluteConstraints(35, 220, 80, 20));

    jLabel7.setFont(new java.awt.Font("Tahoma", 1, 16));
    jLabel7.setForeground(new java.awt.Color(153, 0, 153));
    jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel7.setText("Type");
    getContentPane().add(jLabel7,new AbsoluteConstraints(360, 260, 80, 20));

    jLabel5.setBackground(new java.awt.Color(249, 239, 242));
    jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
    jLabel5.setForeground(new java.awt.Color(153, 0, 153));
    jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel5.setText("Manufacturer");
    getContentPane().add(jLabel5, new AbsoluteConstraints(30,260, 100, 20));

    jLabel6.setBackground(new java.awt.Color(249, 239, 242));
    jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
    jLabel6.setForeground(new java.awt.Color(153, 0, 153));
    jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel6.setText("Cost(RS.)");
    jLabel6.setOpaque(true);
    getContentPane().add(jLabel6, new AbsoluteConstraints(30, 300, 100, -1));

    ItemcodeTF.setFont(new java.awt.Font("Tahoma", 0, 12));
    ItemcodeTF.setForeground(new java.awt.Color(153, 0, 153));
    getContentPane().add(ItemcodeTF, new AbsoluteConstraints(150, 140, 180, -1));

    ItemnameTF.setFont(new java.awt.Font("Tahoma", 0, 12));
    ItemnameTF.setForeground(new java.awt.Color(153, 0, 153));
    getContentPane().add(ItemnameTF,new AbsoluteConstraints(150, 180, 180, -1));

    DescriptionTF.setFont(new java.awt.Font("Tahoma", 0, 12));
    DescriptionTF.setForeground(new java.awt.Color(153, 0, 153));
    getContentPane().add(DescriptionTF, new AbsoluteConstraints(150, 220, 390, -1));

    ManufaturerTF.setFont(new java.awt.Font("Tahoma", 0, 12));
    ManufaturerTF.setForeground(new java.awt.Color(153, 0, 153));
    getContentPane().add(ManufaturerTF, new AbsoluteConstraints(150,260, 180, -1));

    CostTF.setFont(new java.awt.Font("Tahoma", 0, 12));
    CostTF.setForeground(new java.awt.Color(153, 0, 153));
    getContentPane().add(CostTF,new AbsoluteConstraints(150, 300, 180, -1));

    TypeTF.setFont(new java.awt.Font("Tahoma", 0, 12));
    TypeTF.setForeground(new java.awt.Color(153, 0, 153));
    final String labels[] = { "Tablets", "Capsules", "Syrup" };
    final DefaultComboBoxModel model = new DefaultComboBoxModel(labels);
    final JPanel TypeTF = new JPanel();
    JComboBox comboBox1 = new JComboBox(model);
    comboBox1.setEditable(false);
    TypeTF.add(comboBox1);
    getContentPane().add(TypeTF,new AbsoluteConstraints(430, 255, 180, -1));        

    SaveBTN.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.highlight"));
    SaveBTN.setFont(new java.awt.Font("Times New Roman", 1, 16));
    SaveBTN.setForeground(new java.awt.Color(102, 0, 102));
    SaveBTN.setText("SUBMIT");
    SaveBTN.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(255, 204, 255), new java.awt.Color(255, 204, 255), new java.awt.Color(153, 0, 153), new java.awt.Color(153, 0, 153)));
    SaveBTN.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SaveBTNActionPerformed(evt);
        }
    });


    getContentPane().add(SaveBTN, new AbsoluteConstraints(110, 380, 90, 40));

    BackBTN.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.highlight"));
    BackBTN.setFont(new java.awt.Font("Times New Roman", 1, 16));
    BackBTN.setForeground(new java.awt.Color(102, 0, 102));
    BackBTN.setText("BACK");
    BackBTN.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(255, 204, 255), new java.awt.Color(255, 204, 255), new java.awt.Color(153, 0, 153), new java.awt.Color(153, 0, 153)));
    BackBTN.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
          BackBTNActionPerformed(evt);
        }
    });


    getContentPane().add(BackBTN, new AbsoluteConstraints(260, 380, 90, 40));





   this.setSize(600, 600); 
 //pack();   
}

private void SaveBTNActionPerformed(java.awt.event.ActionEvent evt){

      try{

         Class.forName("com.mysql.jdbc.Driver");
         String database = "jdbc:mysql://localhost:3306/medicalstore";
         Connection conn = DriverManager.getConnection(database, "root", "sunil");
         Statement stmt = conn.createStatement(); 



         String sql = "insert into addnewitem values ( '" + ItemcodeTF.getText() + "','" + ItemnameTF.getText() + "' ,'" + DescriptionTF.getText() + "' , '" + ManufaturerTF.getText() + "' , '" + TypeTF.getText() + "' , '" + CostTF.getText() + "' )" ;
         stmt.executeUpdate(sql);

         stmt.close();
         conn.close();



    }

      catch( Exception e)
      {
           JOptionPane.showMessageDialog(null,"" + e);

      }
}

private void BackBTNActionPerformed(java.awt.event.ActionEvent evt){

    add m = new add(ID);
    this.setVisible(false);
    m.setVisible(true);
}
/*
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new ItemDetails().setVisible(true);
        }
    });
}*/

}

View Answers

Ads









Related Tutorials/Questions & Answers:
How to store JComboBox item into database
How to store JComboBox item into database   import...(javax.swing.SwingConstants.CENTER); jLabel2.setText("Item Code"); getContentPane().add(jLabel2,new...); jLabel3.setText("Item Name"); getContentPane().add(jLabel3,new AbsoluteConstraints(27
How to store image into database
How to store image into database  Hi, all I want to store image into database using Java. Can anyone help me that how can i store image into database... through the following link How To Store Image Into MySQL Using Java
Advertisements
How to store an image in database
How to store an image in database  Hi........... How to store an image in postgresql using a query. I mean tell me the way to store an image using datatype. I am using the datatype bytea but tell me how to insert the image
jComboBox with database
my database. But in my code its only get data from first item which...jComboBox with database  Hello friends, I have created three JComboBoxes. first two of them get list from string. However I select these two
Java JComboBox Get Selected Item Value
. In this tutorial we are discussing about how to store the selected item value of JComboBox into the database table. To store the selected item value of JComboBox... how to get the selected item value form JComboBox. javax.swing.JComboBox
Help on database and JComboBox
Help on database and JComboBox  I want to select from the JComboBox...") all the each new york picture and detail will be seen. But how to grab the things from database
How to store and retrieve image from database in JSP?
How to store and retrieve image from database in JSP?  Hi, In one of my application I have to store and then display the image in JSP. How to store and retrieve image from database in JSP? Thanks   HI, You can use
delete an item from database
delete an item from database  how to delete an item from the database using jsp
how to store and then immediately retrieve when store the image into database?
how to store and then immediately retrieve when store the image into database?  how to store and then immediately retrieve when store the image into database?   Here is a jsp code that insert and retrieve image from
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using... database. <%@page import="java.sql.*,java.io.*"%> <% try{ InputStream
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how can i store text box values as it is in database table
how can i store text box values as it is in database table  CUSTOMER DESCRIPTION
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database
how to store and retrieve images int and from the database using php
how to store and retrieve images int and from the database using php  please anyone can help me in storing the images and retrieve it back from the Mysql database using php
JComboBox
JComboBox  I have jcombobox. In which tha values are loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item. Please some one help me to do this. Thank you
how to store JTree data hierarchically in mysql database from netbeans
how to store JTree data hierarchically in mysql database from netbeans  how to store JTree data hierarchically in mysql database from netbeans. I am new to this topics so I need a program and tables you are using in database
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
JComboBox
have jcombobox on Jframe form of IDE. In which the values are to be loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item in JComboBox. Thank you.   import java.sql.
how to store image in folder and stored image path in mysql database using JSP
how to store image in folder and stored image path in mysql database using JSP  how to store image in folder and stored image path in mysql database using JSP
How to store user name,city,state,image path into database and image into folder using jsp
How to store user name,city,state,image path into database and image into folder using jsp  How to store user name,city,state,image path into database and image into folder using jsp
How to store multiple images in folder and images path in database at a time using jsp?
How to store multiple images in folder and images path in database at a time using jsp?  I wanna browse multiple images in one form and store them in one folder and their path into datrabase
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java  How To Store Multilple Images In MySQL database dynamically with image uploader
Jcombobox
Jcombobox  Hii, I am doing my final year project and i am using java swing as a front end.I have used Jcombobox for displaying my on bluetooth... want updated list of on devices in that same combobox.I cant understand how to do
How to get the text from textarea in HTML and store it in database using javascript and jsp
How to get the text from textarea in HTML and store it in database using javascript and jsp  How to get the text from textarea in HTML and store it in database using javascript and jsp <script> function str() { <
JComboBox
JComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
jComboBox
jComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
store and retrive image from the database
store and retrive image from the database  please provide me with the code and the explanation of what each line does for the below query. -how to store and retreive images from sql database using sql commands -how to store

Ads