Returning multiple results in JDBC
i want to get multple data from specific criteria from by mysql , however i'm only getting the first row that meets the criteria ere is the code:
Code:
try
{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/?","?","?");
Statement stat = con.createStatement ();
ResultSet rs = stat.executeQuery("SELECT * FROM ncu_courses WHERE user_name='" + userName +"'");
while (rs.next ())
{
int x = 0;
currentCourses[x] = rs.getString("course");
lecturer [x] = rs.getString("lecturer");
time [x] = rs.getString("time");
day [x] = rs.getString("day");
x++;
}
}
catch (SQLException e)
{
System.out.println ("SQL Error " +e.getMessage ());
e.printStackTrace ();
}