PreparedStatement的setObject()方法 [英] setObject() method of PreparedStatement

查看:325
本文介绍了PreparedStatement的setObject()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以对所有数据类型(例如Stringintdouble)使用PreparedStatementsetObject()方法吗?

Can I use the setObject() method of PreparedStatement for all datatypes (like String, int or double)?

如果使用它,潜在的问题是什么?

What are the potential problems if I use that?

protected void fillStatement(PreparedStatement stmt, Object[] params)
        throws SQLException {

        if (params == null) {
            return;
        }

        for (int i = 0; i < params.length; i++) {
            if (params[i] != null) {
                stmt.setObject(i + 1, params[i]);
            } else {
                stmt.setNull(i + 1, Types.OTHER);
            }
        }
    }

推荐答案

我仅将setObject()与MySQL一起使用,而我从来没有遇到过问题.我不能代表其他数据库或其他供应商.

I use setObject() exclusively with MySQL and I've never had a problem with it. I cannot speak for other databases or other vendors.

这篇关于PreparedStatement的setObject()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆