我有一个与mysql db一起使用的简单程序。我需要切换到oracle db。 我试图将数据插入数据库,但我收到此错误。我试图手动插入数据,每次都很好,但编程上我得到了错误。
这是我的代码。
public void saveHasta(List<Hasta> hastaList) {
try {
// PreparedStatement stmt = connection.prepareStatement("INSERT INTO tblHasta (hasta_tc_kimlik,hasta_isim, hasta_soyisim,hasta_dogum_tarih,hasta_meslek,randevu_ID) VALUES (12345678912, 'Mert', 'Akel', '1995-07-21', 'Yazilim', 2)");
//
// System.out.println("Oldu");
PreparedStatement stmt = connection.prepareStatement("INSERT INTO tblHasta (hasta_tc_kimlik,hasta_isim, hasta_soyisim,hasta_dogum_tarih,hasta_meslek,randevu_ID) VALUES (?,'?','?','?','?',?)");
Iterator<Hasta> it = hastaList.iterator();
while (it.hasNext()) {
Hasta h = it.next();
stmt.setLong(1, h.getTcKimlik());
stmt.setString(2, h.getIsim());
stmt.setString(3, h.getSoyIsim());
stmt.setString(4, h.getDogumTarih());
stmt.setString(5, h.getMeslek());
PreparedStatement pst = connection.prepareStatement(
"SELECT randevu_ID FROM tblRandevu where tc_kimlik = '" + h.getTcKimlik() + "'");
ResultSet rs = pst.executeQuery();
while (rs.next()) {
randevu_id = rs.getInt("randevu_ID");
}
stmt.setInt(6, randevu_id);
stmt.addBatch();
}
stmt.executeUpdate();
System.out.println("Oldu");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是我的表
CREATE TABLE tblhasta
( hasta_ID INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) NOT NULL,
hasta_tc_kimlik INTEGER,
hasta_isim varchar2(50),
hasta_soyisim varchar2(50),
hasta_dogum_tarih varchar2(50),
hasta_meslek varchar2(50),
randevu_ID INTEGER,
CONSTRAINT hasta_pk PRIMARY KEY (hasta_ID)
);
答案 0 :(得分:2)
您以错误的方式使用了预准备语句
PreparedStatement stmt = connection.prepareStatement("INSERT INTO tblHasta (hasta_tc_kimlik,hasta_isim, hasta_soyisim,hasta_dogum_tarih,hasta_meslek,randevu_ID)
VALUES (?,?,?,?,?,?)");
将值更改为
cat