How can i get multiple records from mySQl database
i want to get all the records that has a particular user name from my database and store each into a parallel array. The problem i am having is that its only getting the last record. How can i get the all record ere is an example of the code.
Code :
String [] day = new String [5];
String [] time = new String [5];
String [] course = new String [5];
try
{
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/somedatase","some name","");
Statement state = connect.createStatement ();
ResultSet rs = state.executeQuery("Select * FROM time_table WHERE user_name='" + user +"'");
int x = 0;
while (rs.next ())
{
day[x] = rs.getString("day");
time[x] = rs.getString ("time");
course[x] = rs.getString ("course");
}
connect.close ();
state.close ();
rs.close ();
}//end try
catch (SQLException e)
{
e.printStackTrace ();
}//end catch
Re: How can i get multiple records from mySQl database
Word of advice: map the data to an object - parallel arrays can get ugly very fast. That being said, add some println's to your while loop. If you did this an printed out the variable x, you will realize you never increment this value, and thus continually set index 0 of your arrays for each loop.
Re: How can i get multiple records from mySQl database
didn't reallize i did that thanks alot