daily pastebin goal
51%
SHARE
TWEET

niggawehitthejackpot

a guest Jan 25th, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package JavaDB_001;
  2. import javax.swing.*;
  3. import java.sql.*;
  4.  
  5. public class Test extends JFrame{
  6.     JComboBox jc = new JComboBox();
  7.     JPanel panel = new JPanel();
  8.     Connection con;
  9.     Statement st;
  10.     ResultSet rs;
  11.     public Test()
  12.     {
  13.     this.setSize(400, 400);
  14.     this.setLocationRelativeTo(null);
  15.     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.     try{
  17.       con = DriverManager.getConnection("jdbc:mysql://localhost/test_db","root","");
  18.       st = con.createStatement();
  19.       String s = "select * from users";
  20.       rs = st.executeQuery(s);
  21.         while(rs.next())
  22.         {
  23.             jc.addItem(rs.getString(1)+" === "+rs.getString(2));
  24.         }
  25.     }catch(Exception e){
  26.         JOptionPane.showMessageDialog(null, "ERROR");
  27.     }finally{
  28.         try{
  29.             st.close();
  30.             rs.close();
  31.             con.close();
  32.         }catch(Exception e){
  33.             JOptionPane.showMessageDialog(null, "ERROR CLOSE");
  34.         }
  35.     }
  36.     panel.add(jc);
  37.     this.getContentPane().add(panel);
  38.     this.setVisible(true);
  39.     }
  40.  
  41. public static void main(String[] args){
  42.             new Test();
  43.   }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top