Cześć, mam problem więc tak:
Chce aby wywalało mi tylko jedną kolumne jak widać "Cene".
public static ArrayList<Samochod> selectSamochod_CenaColumn()
{
ArrayList<Samochod> l = new ArrayList<Samochod>();
String select = "SELECT Cena FROM Samochod";
try {
ResultSet rs = stat.executeQuery(select);
while (rs.next()) //dopoki jest nastepny wiersz
{
int cena = rs.getInt("cena");
}
return l;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
Lecz mam problem ponieważ w klasie samochod mam konstruktor. W poprzedniej metodzie zwykłego selecta wygląda to tak
public static ArrayList<Samochod> selectSamochod()
{
ArrayList<Samochod> l = new ArrayList<Samochod>();
String select = "SELECT * FROM Samochod";
try {
ResultSet rs = stat.executeQuery(select);
while (rs.next()) //dopoki jest nastepny wiersz
{
int id = rs.getInt("id");
String marka = rs.getString("marka");
int cena = rs.getInt("cena");
double pojemnosc = rs.getDouble("pojemnosc");
int konie = rs.getInt("konie");
String kolor = rs.getString("kolor");
Samochod s = new Samochod(id, marka, cena, pojemnosc, konie, kolor);
l.add(s);
}
return l;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}