JAVA - How To Bind A List With MySql Database Data In Java
Project Source Code:
package JavaDB_001; import java.awt.Color; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import javax.swing.*; import java.sql.Statement; import java.awt.List; public class Work extends JFrame{ List list; public Work(){ list = new List(); list.setBounds(20,20,440,420); BindList(); add(list); setLayout(null); setSize(500, 500); getContentPane().setBackground(Color.decode("#bdb76b")); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } //create A function To Bind The List With MySql Database public void BindList(){ Connection con; Statement st; ResultSet rs; try{ con = DriverManager.getConnection("jdbc:mysql://localhost/test_db","root",""); st = con.createStatement(); rs = st.executeQuery("select * from users"); while(rs.next()){ list.add(rs.getString(2)); } }catch(Exception ex){ ex.printStackTrace(); } } public static void main(String[] args){ new Work(); } } ///////////////END /////OUTPUT:
Populate A List With MySql Database Values In Java |
Download Projects Source Code