2015-10-20 207 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