Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在使用 hutool DB时的一些疑惑 #3654

Closed
xiaoACE6716 opened this issue Jul 13, 2024 · 3 comments
Closed

在使用 hutool DB时的一些疑惑 #3654

xiaoACE6716 opened this issue Jul 13, 2024 · 3 comments
Labels

Comments

@xiaoACE6716
Copy link

版本情况

JDK版本: jdk_8_311
hutool版本: 5.8.27

问题描述(包括截图)

hutool DB 与 sqlite 搭配使用时,即使数据类型对不上也能插入成功?下面是测试代码和Navicat中看到的情况,如果直接在Navicat写插入语句是无法插入的

  1. 复现代码 (测试时我直接写死了传入的内容)
    public static int addProduct(String name, int price, int num) {
        try {
            return Db.use().insert(Entity.create("product").set("cid", "test01").set("name", "test02").set("price", "test03").set("num", "test04"));
        } catch (SQLException e) {
            return 0;
        }
    }

image
表结构
image

@looly
Copy link
Member

looly commented Jul 13, 2024

经过测试,确实会在定义int类型字段中插入字符串。

应该是Sqlite的JDBC驱动没有做类型检查导致的。

Hutool对参数本质上是调用的PreparedStatement.setObject,如果驱动未做类型检查,那可能就直接插入。

@looly
Copy link
Member

looly commented Jul 13, 2024

@xiaoACE6716 我给sqlite-jdbc 提issue了,你可以随时关注:

xerial/sqlite-jdbc#1143

@looly looly closed this as completed Jul 13, 2024
@looly looly added the question label Jul 13, 2024
@looly
Copy link
Member

looly commented Jul 15, 2024

@xiaoACE6716

image

简洁ming明了的回答。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants