Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CategoryItem
- {
- int id;
- String name;
- // add other fields if you want...
- CategoryItem(int id, String name)
- {
- this.id = id;
- this.name = name;
- }
- public String toString()
- {
- return name;
- }
- }
- public void LoadCategory()
- {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con1 = DriverManager.getConnection("jdbc:mysql://localhost/javapos","root","");
- insert = con1.prepareStatement("SELECT * FROM category");
- ResultSet rs = insert.executeQuery();
- jComboBox1.removeAllItems();
- while(rs.next())
- {
- jComboBox1.addItem(CategoryItem(rs.getInt(1),rs.getString(2)));
- }
- }
- catch (Exception e) {
- }
- }
- String name =txtproduct.getText();
- String dec =txtdec.getText();
- CategoryItem item = (CategoryItem)jComboBox1.getSelectedItem();
- Class.forName("com.mysql.jdbc.Driver");
- con1 = DriverManager.getConnection("jdbc:mysql://localhost/javapos","root","");
- insert = con1.prepareStatement("insert into product (productname,description,category)values(?,?,?)");
- insert.setString(1,name);
- insert.setString(2,dec);
- insert.setInt(3,item.id);
- insert.executeUpdate();
- JOptionPane.showMessageDialog(this, "Sucsessfully Saved");
Add Comment
Please, Sign In to add comment