
how to populate jlist with all the data retrieved from the ms access database?plzz help

Here is an example that retrieves the countries name from the MS Access database and shows into jlist. Here data is our dsn name.
import java.awt.*;
import java.sql.*;
import javax.swing.*;
public class JListExample extends JFrame {
JPanel panel = new JPanel();
public JListExample() {
panel.setLayout(null);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:data");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from countries");
String data = "";
while (rs.next()) {
data += rs.getString("countryname") + " ";
}
String db[] = data.split(" ");
final JList list1 = new JList(db);
JScrollPane pane1 = new JScrollPane(list1);
pane1.setBounds(10, 10, 100, 100);
panel.add(pane1);
add(panel);
setSize(250, 150);
setVisible(true);
} catch (Exception e) {
}
}
public static void main(String[] args) {
new JListExample();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.