Hi! I want to read a table from Access to Java.
This is the table:
http://kepfeltoltes.hu/090221/heights_www.kepfeltoltes.hu_.jpg
I tried to do it with HashMap, but I have a problem, and I don't even know what im doing is right, I have no practice in this, altough I've been trying to find a solution for like a week. I made a class for the column names, like this:
class HeightStats{
public int agee;
public int heightt1;
public int heightt2;
public int heightt3;
public int heightt4;
public int heightt5;
public int heightt6;
public HeightStats(int age, int h1, int h2, int h3, int h4, int h5, int h6){
agee = age;
heightt1=h1;
heightt2=h2;
heightt3=h3;
heightt4=h4;
heightt5=h5;
heightt6=h6;
}
}
This is my code:
String sql_mag = "SELECT * FROM STATS";
try
{
Statement statement = con.createStatement ();
ResultSet rs;
rs = statement.executeQuery (sql_mag);
int index=0;
if (rs != null)
{
while (rs.next())
{
HashMap hMap = new HashMap();
String s = hMap.toString();
hMap.put(index,new HeightStats(rs.getInt(1),rs.getInt(2),rs.getInt(3),rs.getInt(4),rs.getInt(5),rs.getInt(6), rs.getInt(7)));
index++;
Collection c;
c = hMap.values();
Iterator itr = c.iterator();
System.out.println(hMap.toString());
}
}
rs.close ();
statement.close();
} catch (Exception ex)
{
System.out.println("Error reading database information!");
System.out.println(ex);
}
}
And the output says:
Success!
{0=project1.HeightStats@a0dcd9}
{1=project1.HeightStats@1034bb5}
{2=project1.HeightStats@15f5897}
{3=project1.HeightStats@b162d5}
{4=project1.HeightStats@1cfb549}
Any help is appreciated.