2015-10-20 208 views
-2

我有一个问题,我的查询我不知道如何处理甲骨文,但是当我尝试相同的代码的SQL它的工作,但它显示我上面的错误编译我认为问题是在查询中,请有人帮助,如果知道如何处理这个。 感谢SQL状态[null];错误代码[17004];无效的列类型;嵌套的异常是java.sql.SQLException:无效列类型

//一流

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", "[email protected]", "GG"); 
      Offer offer2 = new Offer(11, "khan", "[email protected]", "GG"); 
      Offer offer3 = new Offer(12, "khan", "[email protected]", "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(); 
    } 

} 
+1

如果您认为问题与查询有关,那么实际包含它可能是一个好主意......包含表定义也是一个好主意(一个或多个)查询正在击中的表格。 – JonK

+0

没有发布相关的代码,没有人可以帮助你。 Downvoting。您可以通过阅读http://stackoverflow.com/help/how-to-ask以及如何通过阅读以下内容创建示例来参考如何提出问题:http://stackoverflow.com/help/mcve –

+0

@JonK谢谢兄弟,我想包括我的整个Java类,但由于一些奇怪的原因不工作..查询是返回jdbc.update(“INSERT INTO offers”+“(id,name,email,text)”+“VALUES”+“ (:id,:name,:email,:text)“,params)== 1; – Faisal

回答

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

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

+0

你的代码现在开放给SQL注入 – Miquel