Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to store JComboBox item into database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sunil singh
How to store JComboBox item into database
0 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


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);
        }
    });
}*/

}


Advertisement
View Answers

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 JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend..."); f.getContentPane().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc
Advertisements
How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try...().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc=new
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
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
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
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
delete an item from database
delete an item from database  how to delete an item from the database using jsp
Database values in JComboBox
Database values in JComboBox In this section, you will learn how to display values in JComboBox from database. For this, we have allowed the user to enter... the database will get displayed on the ComboBox. If there will be  no data
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
navigation between panels when item is selected from jcombobox - Swing AWT
navigation between panels when item is selected from jcombobox  hi...(2nd panel).the combo box is in main panel. when a item is selected from combobox the 2nd panel should navigate to other panel. for now i have 4 item in the combo
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
Link To Database with JComboBox - Java Beginners
Link To Database with JComboBox  sir As ur Source Code i have Load course names from Access Database in to JComboBox but now I want to do ,when i select Course name from Jcombobox i want to display appropriate records relate
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
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 extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example
How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example
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 change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
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 store values in a database using JSTL? - JSP-Servlet
How to store values in a database using JSTL?  I want to store values in a database... How can i store in database? Here is my code... This wil... in a database...How can i do? Airport
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
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
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.
binding jComboBox to mysql database - Swing AWT
binding jComboBox to mysql database  I am using netbeans 6.5 How to populate jComboBox with data of specific column of mysql database table? I...){ e.printStackTrace(); } JComboBox comboTypesList = new
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 Store Float Value into Access Database - Java Beginners
How to Store Float Value into Access Database  Hello sir,I want to Store Student Marks Percentage into Access Database in Float Value how i can Store.... To store the double value in Access database, you need to set the datatype
Advertisements
 

 

 

DMCA.com