SQL状态[null];错误代码[17004];列类型无效;嵌套异常为java.sql.SQLException:列类型无效
我的查询有问题,我不知道如何处理oracle,但当我尝试使用相同的SQL代码时,它工作正常,但在编译时它向我显示了上述错误。我认为问题出在查询中,如果知道如何处理,请有人帮助。 谢谢 //头等舱SQL状态[null];错误代码[17004];列类型无效;嵌套异常为java.sql.SQLException:列类型无效,java,spring,oracle,Java,Spring,Oracle,我的查询有问题,我不知道如何处理oracle,但当我尝试使用相同的SQL代码时,它工作正常,但在编译时它向我显示了上述错误。我认为问题出在查询中,如果知道如何处理,请有人帮助。 谢谢 //头等舱 package com.caveofprogramming.spring.test; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource;
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();
}
}
而不是
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;
}
现在它是这样工作的。
好吧,这不是我的答案,但无论如何,这是我发现的处理上述错误的另一种方式,但我仍然没有找到什么可能是错误在前面的查询。
感谢你们所有的朋友:)快乐编码如果你认为问题出在查询上,那么实际包含它可能是个好主意。。。。包含查询所命中的表的表定义也是一个好主意。如果不发布相关代码,没有人可以帮助您。否决票。您可以通过检查来询问问题,以及通过阅读以下内容来创建示例:@JonK谢谢兄弟,我正试图包含我的整个java类,但由于一些奇怪的原因无法工作。。查询返回jdbc.update(“插入到报价中”+“(id,name,email,text)”+“值”+”(:id,:name,:email,:text)”,参数)==1@Faisal@jonk bro我认为此功能中存在错误,公共布尔创建(Offer Offer){BeanPropertySqlParameterSource params=new BeanPropertySqlParameterSource(Offer);返回jdbc.update(“插入到offers(id,name,email,text)值(:id,:name,:email,:text)”,params==1;}//因为为什么它对oracle不起作用虽然我尝试直接放置数据它起作用,但当我尝试传递对象时却不起作用,所以我完全失望了:(兄弟,知道可能是什么问题吗。?提前谢谢
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;
}