1

What is the best way to get my mysql data into a JList. I can connect to the database and output the results. I've been looking at various ways online but not getting the desired results. Instead of posting any code, are there any great tutorials showing how this is done, or any code snips.

    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection
        ("jdbc:mysql://www", "....", "....");

        st = con.createStatement();

        } catch (Exception ex) {
        System.out.println("error" + ex);
        }
        try {           

            String query = "select * from demo";
            rs = st.executeQuery(query);
            System.out.println("Records from Database");
            while(rs.next()) {                      
            String number  = rs.getString("number");
            System.out.println(number);         

            }
        } catch (Exception ex) {

        System.out.println("error" + ex);
        }
    }       
}

3 Answers 3

4

It looks like you understand how to query the database using JDBC. Now you just need to use the results to construct your preferred ListModel, as shown in How to Use Lists.

Sign up to request clarification or add additional context in comments.

Comments

2

I use a spring class called SimpleJdbcTemplate that you can use to query the database. Its fairly lightweight but avoids having to set up the XML mappings needed in Mybatis! or Hibernate.

Here is a fairly comprehensive tutorial .

Comments

0

Mybatis! or Hibernate - for the shortest answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.