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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.