public void FillList() { try { String sql1 = "select * from motors"; Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt = con.createStatement(); ResultSet rs1 = stmt.executeQuery(sql1); DefaultListModel DLM = new DefaultListModel(); while (rs1.next()) { DLM.addElement(rs1.getString(3)); // DLM.addElement(rs1.getString(2)); } List.setModel(DLM); } catch (Exception e) { JOptionPane.showMessageDialog(null, "e.getString()"); } }