Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 14th, 2012  |  syntax: Java  |  size: 1.38 KB  |  hits: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ///Populate jComboBox
  2. private void FillCombo(){
  3.         String sql = "Select ID_osoba, Ime, Prezime from osoba";
  4.         try{
  5.             pst = conn.prepareStatement(sql);
  6.             rs = pst.executeQuery();
  7.             while (rs.next()){
  8.                 String nme = rs.getString("Ime");
  9.                 String gg = rs.getString("ID_osoba");
  10.                 String ggg = rs.getString("Prezime");
  11.                 int gggg = rs.getInt("ID_osoba");
  12.                 jComboBox1.addItem(gggg +"."+" "+" "+ nme +" "+ ggg);                
  13.             }
  14.         }
  15.             catch(Exception e){
  16.                 JOptionPane.showMessageDialog(null, e);
  17.         }
  18.     }
  19. ///Insert into database
  20. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  21.     conn = Connect.ConnectDB();
  22.                
  23.         String sql = "INSERT INTO adresa (Naziv_ulice, Br_ulice, ID_Osoba_FK, Id_grad_FK) VALUES ('"+ULICA.getText()+"','"+BROJUL.getText()+"','"+jComboBox1.getSelectedObjects()+"','"+jComboBox2.getItemAt(WIDTH) +"')" ;
  24.         try{
  25.             pst = conn.prepareStatement(sql);
  26.             pst.execute();
  27.             JOptionPane.showMessageDialog(null, "Saved");
  28.            
  29.             UpdateJTable();
  30.             //conn.close();
  31.         }
  32.         catch(Exception e){
  33.             JOptionPane.showMessageDialog(null, e);
  34.         }
  35. }