public class
DBdataintoArraylist {
public void studentData() throws SQLException,
ClassNotFoundException {
List<GetDBvaluesofAllDatatypes>
list = new ArrayList<GetDBvaluesofAllDatatypes>();
String driver = "com.mysql.jdbc.Driver";
String dburl = "jdbc:mysql://localhost/test";
String usrname = "root";
String pswd = "root";
String query = "SELECT *
FROM Student WHERE section='A'";
Class.forName(driver);
Connection conn = DriverManager.getConnection(dburl,
usrname, pswd);
Statement stmt =
conn.createStatement();
ResultSet rs =
stmt.executeQuery(query);
while (rs.next()) {
GetDBvaluesofAllDatatypes gdb
= new
GetDBvaluesofAllDatatypes(
rs.getString("First_Name"), rs.getString("Last_Name"), rs.getInt("marks"),
rs.getString("Grade"), rs.getString("Section"), rs.getString("Birth_Date"));
list.add(gdb);
}
for
(GetDBvaluesofAllDatatypes gdb : list) {
System.out.println(gdb.getFname());
System.out.println(gdb.getLname());
System.out.println(gdb.getGrade());
System.out.println(gdb.getMarks());
System.out.println(gdb.getSection());
System.out.println(gdb.getDate());
}
}