繁体   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

我的查询有问题我不知道如何处理 oracle 但是当我为 SQL 尝试相同的代码时它正在工作但它在编译时向我显示上述错误我认为问题出在查询中,如果有人帮忙知道如何处理这个问题。 谢谢

// 第一类

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

// 第二类

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 + "]";
    }

}

//第三个主类

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;

 }

代替

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

现在它就是这样工作的。 好吧,这不是我的答案,但无论如何这是我发现的以另一种方式处理上述错误的方法,但我仍然没有发现上一个查询中的错误可能是什么。 感谢你们所有的朋友 :) 快乐编码

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM