Thursday, October 25, 2012

Code used in video "Java prog#6. How to link jcombobox with database in Netbeans Java and Sqlite (mysql)"


Here I am providing the downloadable code link of  the java code I have used in the video  "Java prog#6. How to link jcombobox with database in Netbeans Java and Sqlite (mysql)"  of my YouTube channel ProgrammingKnowledge


Click Link to watch the video LINK


This code below is for the Fillcombo() method action perform



private void Fillcombo(){
 
 
try{
  String sql="select * from Empoyeeinfo";
  pst=conn.prepareStatement(sql);
   rs=pst.executeQuery();
 
   while(rs.next()){
   String name =rs.getString("name");
   ComboBox_name.addItem(name);
 
   }

}catch(Exception e){

JOptionPane.showMessageDialog(null, e);

} finally {
try{
  rs.close();
      pst.close();
    // conn.close();
  }
  catch(Exception e) {
                   }
      }

}


Java prog#6. How to link jcombobox with database in Netbeans Java and Sqlite (mysql)




Jave Netbeans and Sqlite (mysql) populate jcombobox

In this video I have tried to show how to use jcombobox with database
ComboBox for Java using NetBeans
java netbeans and mysql  populate combo box
binding jComboBox to mysql database
How to get the selected Text in JComboBox?
populating combo box
Fill JComboBox with MySQL data Netbeans
Adding items to a jComboBox
Populating Combo Box Selections With NetBeans - Java
Fill JComboBox with MySQL data
Java - JComboBox - Obtain Values
How Use the Combo Box With Netbeans GUI
Combo Box in Netbeans
java - How do I populate jcombobox from a textfile?
jComboBox demo
Netbeans IDE Users - JCombo Box using Net Beans
How To Add Jcombobox List From Database?
link jcombobox with database
Jcombobox with database help
JAVA - How do I populate a jcombobox with information from a mySQL database?
iit Learn     java netbeans
java tutorial netbeans

2 comments:

  1. I appreciated your tutorials. This is my code at the bottom. I tried a lot, I don't see any errors, but it's just not connecting with SQLite for jComboBox dropdown list. I do have multiple jComboBox for the code. Can you please help.


    package Main;

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import javax.swing.JOptionPane;

    public class User_Page extends javax.swing.JFrame {
    String loggedInUser = null;
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement ps = null;

    public User_Page() {
    initComponents();
    myInit();
    Fillcombo();
    conn = DB_Connect.ConnectDB();

    }

    @SuppressWarnings("unchecked")
    private void myInit(){

    }

    private void Fillcombo(){


    try{
    String sql="select * from quaterTable";
    ps=conn.prepareStatement(sql);
    rs=ps.executeQuery();

    while(rs.next()){
    String name =rs.getString("name");
    quaterComboBox.addItem(name);
    }

    } catch(Exception e){

    JOptionPane.showMessageDialog(null, e);

    } finally {
    try{
    rs.close();
    ps.close();
    // conn.close();
    }
    catch(Exception e) {
    }
    }

    }


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
    * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClassName());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(User_Page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(User_Page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(User_Page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(User_Page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    User_Page userPage = new User_Page();
    userPage.setVisible(true);


    }
    });
    }

    ReplyDelete
  2. Thanks a million for simple code that does simple things. Most of the time someone is looking a simple thing like fill a combo box and the web has so much more complicated stuff for beginners

    ReplyDelete