简体   繁体   English

SQL 状态 [null]; 错误代码 [17004]; 列类型无效; 嵌套异常是 java.sql.SQLException: Invalid column type

[英]SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type

i have a problem with my query i don't know how to deal with oracle but when i try the same code for SQL it's working but it's showing me the above error while compiling i think the problem is in the query , please someone help if knew how to deal with this.我的查询有问题我不知道如何处理 oracle 但是当我为 SQL 尝试相同的代码时它正在工作但它在编译时向我显示上述错误我认为问题出在查询中,如果有人帮忙知道如何处理这个问题。 thanks谢谢

// First class // 第一类

package com.caveofprogramming.spring.test;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Component;

    @Component
    ("offersDao")
    public class OffersDAO {
        private JdbcTemplate jdbc;
        @Autowired`enter code here`
        public void setDataSource(DataSource jdbc) {
            this.jdbc = new JdbcTemplate(jdbc);
        }
    public boolean create(Offer offer) {
    BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(offer);
    return jdbc.update("INSERT INTO offers " + " ( id, name, email, text) "
                    + " VALUES " + " ( :id, :name, :email, :text) ", params) == 1;
    }
    }

// 2nd class // 第二类

package com.caveofprogramming.spring.test;

public class Offer {

    private int id;
    private String name;
    private String email;
    private String text;

    public Offer() {

    }

    public Offer(int id, String name, String email, String text) {

        this.id = id;
        this.name = name;
        this.email = email;
        this.text = text;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    public String toString() {
        return "Offer [id=" + id + ", name=" + name + ", email=" + email
                + ", text=" + text + "]";
    }

}

//3rd main class //第三个主类

package com.caveofprogramming.spring.test;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.CannotGetJdbcConnectionException;

public class App {

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext(
                "com/caveofprogramming/spring/test/beans/beans.xml");

        OffersDAO offersDao = (OffersDAO) context.getBean("offersDao");

        try {

            Offer offer1 = new Offer(10, "khan", "G@G.com", "GG");
            Offer offer2 = new Offer(11, "khan", "M@G.com", "GG");
            Offer offer3 = new Offer(12, "khan", "V@G.com", "GG");
            offersDao.create(offer1);
            offersDao.create(offer2);
            offersDao.create(offer3);

        } catch (CannotGetJdbcConnectionException ex) {
            System.out.println("Unable to connect to database");
        } catch (DataAccessException ex) {
            System.out.println(ex.getMessage());
            System.out.println(ex.getClass());
        }

        ((ClassPathXmlApplicationContext) context).close();
    }

}
  i tried 





       public boolean create (Offer offer){

        return jdbc.update("insert into offers (firstno,secondno,thirldno) values
     ( '" +offer.getFirstno() + "', '" +offer.getSecondno() +"' ,'"+offer.getThirldno()+"')")==1;

 }

instead of代替

  public boolean create(Offer offer) {
    BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(offer);
    return jdbc.update("INSERT INTO offers " + " ( id, name, email, text) "
                    + " VALUES " + " ( :id, :name, :email, :text) ", params) == 1;
    }

and now it's working that way .现在它就是这样工作的。 Well , it's not answer to me but anyhow this is what i find out to deal with the above error an another way but i still didn't find out what could be the error in the previous query .好吧,这不是我的答案,但无论如何这是我发现的以另一种方式处理上述错误的方法,但我仍然没有发现上一个查询中的错误可能是什么。 thanks to ALL of you friends :) Happy Coding感谢你们所有的朋友 :) 快乐编码

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

相关问题 日期格式错误java.sql.SQLException:列类型无效 - Date Format Error java.sql.SQLException: Invalid column type 嵌套的异常为java.sql.SQLException:无效的列名ORACLE - nested exception is java.sql.SQLException: Invalid column name ORACLE SQL 状态 [99999]; 错误代码 [17004]; 无效的列类型:1111 使用 Spring SimpleJdbcCall - SQL state [99999]; error code [17004]; Invalid column type: 1111 With Spring SimpleJdbcCall Spring Data JPA查询给出java.sql.SQLException:无效的列类型错误 - Spring Data JPA Query gives java.sql.SQLException: Invalid column type error java.sql.SQLException:无效的列名 - java.sql.SQLException: Invalid column name java.sql.SQLException:无效的列索引 - java.sql.SQLException: invalid column index java.sql.SQLException:无效的列索引 - java.sql.SQLException: Invalid column index java.sql.SQLException:内部错误:无效的类型oid? - java.sql.SQLException: Internal Error: Invalid type oid? 调用 Oracle 存储过程引发:java.sql.SQLException:无效的列类型:1111 - Calling Oracle Stored Procedure throws Caused by: java.sql.SQLException: Invalid column type: 1111 java.sql.SQLException:从 jdbc 执行包级别类型的过程时列类型无效 - java.sql.SQLException: Invalid column type when executing procedure with package level types from jdbc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM