Witam. Chcę dodać do swojej tabeli datę. Mam taką tabelę:
create table loty (
id_lotu number(6,0) constraint loty_pk primary key,
data date,
czas number(6,0),
id_samolotu number(6,0) constraint l_samoloty_fk references samoloty(id_samolotu),
id_pilota number(6,0) constraint l_piloci_fk references piloci(id_pilota),
id_grupy number(6,0) constraint l_grupy_fk references grupy(id_grupy),
id_instruktora number(6,0) constraint l_instruktorzy_fk references instruktorzy(id_instruktora)
);
gdzie jest zmienna data typu date. Chcę w swoim programie wykonać zapytanie uzupełniające tą tabelę wpisem. Wszystko wprowadza się poprawnie poza zmienną typu date:
void dodaj() {
String sql = "INSERT INTO loty(data, czas, id_samolotu, id_pilota, id_grupy, id_instruktora) VALUES (?,?,?,?,?,?)";
ResultSet dane = bd.getData("Select * from loty");
String czas;
String data;
PreparedStatement sta;
data = JOptionPane.showInputDialog(null, "Wprowadź date w formacie dd-mm-yyyy");
czas = JOptionPane.showInputDialog(null, "Wprowadź czas w godzinach");
try {
sta = bd.con.prepareStatement(sql);
sta.setString(1, data);
sta.setInt(2, Integer.parseInt(czas));
sta.setInt(3, Integer.parseInt(id_s));
sta.setInt(4, Integer.parseInt(id_p));
sta.setInt(5, Integer.parseInt(id_g));
sta.setInt(6, Integer.parseInt(id_i));
sta.executeUpdate();
JOptionPane.showMessageDialog(null, "Wpis został dodany");
sta.close();
}
}
}
Podaję datę w tym formacie np 10-12-2010, jednak dostaję błąd: ora-01830 date format picture ends before converting entire input string
Jak można w jakiś sensowny sposób to zrobić? Bo szukam i próbuje, ale jakoś nic nie wychodzi. Proszę o pomoc.