SQLite截断我的数据

时间:2018-08-01 11:05:57

标签: java database sqlite

控制台中的数据如下:

"to add: 
rand_num = 1-231881-6-70885-12
name = heat boy
type = caucasian
price = 700.0
date = 2018-08-01"

相反,出于某种原因我在数据库中得到了这个信息:

"to add: 
rand_num = 1-231881-6-70885-12
name = heat boy
type = caucasian
price = 70"

我的控制器:

public class Controller {
    private description =   "to add: \n"+
                            "rand_num = 1-231881-6-70885-12 \n"+
                            "name = heat boy \n"+
                            "type = caucasian \n"+
                            "price = 700.0 \n"+
                            "date = 2018-08-01"


    private Model textFields() {
        Model model = new Model();
        model.setRand_num(description.getText());
    }
    try {
        DAOClass daoClass = new DAOCLass();
        daoClass.insert(textFields());
    }
    catch(SQLException e){
        System.out.println(e);
    }catch(ClassNotFoundException e) {
        System.out.println(e);
    }
}

我的模特:

public class model {
    private SimpleStringProperty description;


    public Model() {
        this("");
    }    


    public model(String description) {
        super();
        this.rand_num = new SimpleStringProperty(description);
    }

    //getter
        public String getDescription() {
            return description.get();
        }
    //setter
       public void setDescription(String description) {
            this.description.set(description);
        }   
    //property
    public StringProperty descriptionProperty(){
        return description;
    } 

    @Override
    public String toString() {
        return "to add: " + 
    }
}

DAO类

public class DAO {
    public void insert(Model model) throws SQLException, ClassNotFoundException {
        //initializing PreparedStatement
        PreparedStatement preparedStatement = null;

        String updateQuery =
                        "INSERT INTO modelDB \n" +
                        "(description) \n" +
                        "VALUES \n" +
                        "(?)";

        //Execute DELETE operation
        try {
            preparedStatement = connection.prepareStatement(updateQuery);

            preparedStatement.setString(1, model.description());

            preparedStatement.executeUpdate(); 
        } catch (SQLException e) {
            System.out.print("Error: " + e);
            throw e;
        }
        finally {
            if(preparedStatement != null)
            {
                preparedStatement.close();
            }
        }          
    }
} 

我的SQLite表结构:

CREATE TABLE userActivityLogs (
    logId           INTEGER         PRIMARY KEY AUTOINCREMENT,
    description        VARCHAR (10000)
);

现在,我知道SQLite没有限制,即使我使用varChar(10000)也是如此。所有这些都完美地显示在控制台上,但是一旦它进入数据库,它就会被截断。为什么会这样,如何解决此问题?

1 个答案:

答案 0 :(得分:0)

我没有看到您的随机数被截断,所以这里的varchar(10000)不在起作用。

我在您的代码中看到的是:

preparedStatement.setString(4, model.getPrice());
preparedStatement.setString(4, model.getDate());

您使用相同的价格和日期索引。