Hallo Leute
Komme nicht darauf wie ich mein ArrayList mit den Daten in der while schleife füllen soll
Dankbar für jede Hilfe
Komme nicht darauf wie ich mein ArrayList mit den Daten in der while schleife füllen soll
Code:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
public class UserMsg
{
private int id;
private String date;
private String title;
private String role;
private String msg;
private String altMsg;
private ArrayList newsArrayList;
private static DBUser dbUser;
public UserMsg ()
{
createNews ();
}
public String getAltMsg ()
{
return altMsg;
}
public void setAltMsg (String altMsg)
{
this.altMsg = altMsg;
}
public String getDate ()
{
return date;
}
public void setDate (String date)
{
this.date = date;
}
public int getId ()
{
return id;
}
public void setId (int id)
{
this.id = id;
}
public String getMsg ()
{
return msg;
}
public void setMsg (String msg)
{
this.msg = msg;
}
public String getRole ()
{
return role;
}
public void setRole (String role)
{
this.role = role;
}
public String getTitle ()
{
return title;
}
public void setTitle (String title)
{
this.title = title;
}
public void createNews ()
{
try
{
dbUser = new DBUser();
final Connection conn = dbUser.getConnection ();
newsArrayList = new ArrayList ();
Statement statement = conn.createStatement ();
ResultSet rSet = statement.executeQuery ("SELECT * from News");
while (rSet.next ())
{
setId (rSet.getInt ("id"));
setAltMsg (rSet.getString ("altMsg"));
setDate (rSet.getString ("date"));
setMsg (rSet.getString ("msg"));
setRole (rSet.getString ("role"));
setTitle (rSet.getString ("title"));
newsArrayList.add (); //???????????
}
rSet.close ();
statement.close ();
conn.close ();
}
catch (SQLException e)
{
}
}
public Collection getNews ()
{
return newsArrayList;
}
}
Dankbar für jede Hilfe