简体   繁体   English

无效的列索引错误oracle db java

[英]Invalid column index error oracle db java

I have simple program that works with mysql db. 我有与mysql db一起使用的简单程序。 I need to switch to oracle db. 我需要切换到oracle db。 I am trying to insert data into database but I'm getting this error. 我试图将数据插入数据库,但出现此错误。 I tried manually to insert data everyting is fine but programatically I got error. 我尝试手动插入数据,一切都很好,但是从编程上却出现错误。

This is my code. 这是我的代码。

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();
        }

    }

This is my table 这是我的桌子

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)
);

You have used the prepared statements in a wrong way 您以错误的方式使用了准备好的语句

PreparedStatement stmt = connection.prepareStatement("INSERT INTO tblHasta (hasta_tc_kimlik,hasta_isim, hasta_soyisim,hasta_dogum_tarih,hasta_meslek,randevu_ID) 
VALUES (?,'?','?','?','?',?)");

Change values to 将值更改为

PreparedStatement stmt = connection.prepareStatement("INSERT INTO tblHasta (hasta_tc_kimlik,hasta_isim, hasta_soyisim,hasta_dogum_tarih,hasta_meslek,randevu_ID) 
VALUES (?,?,?,?,?,?)");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java中的Oracle连接(错误是无效的列名) - Oracle connection in java (error is invalid column name) 以下Oracle错误是什么意思:无效的列索引 - What does the following Oracle error mean: invalid column index 从oracle 10g数据库获取数据时,java中的无效列索引错误。 不能找出问题所在 - invalid column index error in java while fetching data from oracle 10g database. Cant figure out whats wrong 在Java中调用oracle PL / SQL函数-无效的列类型错误 - calling oracle PL/SQL function in java - Invalid column type error Spring JDBC和Oracle DB 12c:java.sql.SQLException:无效的列类型。 为什么? - Spring JDBC & Oracle DB 12c: java.sql.SQLException: Invalid column type. Why? Java - Oracle - DB Insert - Timestamp to Date 列 - Java - Oracle - DB Insert - Timestamp to Date column java.sql.SQLException:无效的列索引 - java.sql.SQLException: invalid column index java.sql.SQLException:无效的列索引 - java.sql.SQLException: Invalid column index 通过Java执行SQL查询时,获取错误为“ java.sql.SQLException:无效的列索引” - Getting error as “ java.sql.SQLException: Invalid column index” while executing SQL query through java Oracle + Spring安全认证:SQLException:无效的列索引 - Oracle+Spring Security Authentication: SQLException: Invalid column index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM