我的查询有问题我不知道如何处理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 + "]";
}
}
//第3主要课程
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();
}
}
答案 0 :(得分:0)
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;
}
现在它以这种方式工作。 好吧,它没有回答我,但无论如何这是我发现以另一种方式处理上述错误,但我仍然没有找到上一个查询中可能出现的错误。 感谢各位朋友:) Happy Coding