I am attempting to take 2 integers from a MySql table.
X represents a number that will be stored into an array.
Y represents the number of times that X will be put into the array.
I am attempting to make a loop that will go through, find all the Xs, along with their corresponding Ys and store X into an array Y amount of times...
This is an example of what I have been attempting...
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
// Selects the highest index of X so all Xs get stored into array
ResultSet rs = st.executeQuery("SELECT MAX(X) FROM table");
int[] mainArray = {};
int maxIndex = (Integer) rs.getObject(1);
int j = 0;
for (int i = 0; i < maxIndex; i++){
// Selects amount of times to insert given X into array
ResultSet rs2 = st.executeQuery("select Y from table where X = '"+i+"'");
int numberOfEntries = (Integer)rs2.getObject(1);
While(j < numEntries + temp){
mainArray[j] = i;
j++;
}
int temp = j;
}
}catch(Exception e1){
System.out.println(e1);
}
Though, I have gotten every syntax error possible for what I am trying to do.
I have attempted user rs.next() with my result sets and for some reason can not figure out how to in the right syntax.
Can someone show me how to do what I am trying to do?
Thanks tons,
peace and love
oldezwe