【问题标题】:org.postgresql.util.PSQLException: ERROR: invalid input syntax for type inet:org.postgresql.util.PSQLException:错误:inet 类型的输入语法无效:
【发布时间】:2012-04-02 06:18:57
【问题描述】:

我正在尝试从 Java 项目中将 ipaddress 插入到 Postgres 表中。

String ipIns = "INSERT INTO trusted_domains(id, from_ip, to_ip) VALUES (?, ?, ?);";
pstmt = conn.prepareStatement(ipIns);
pstmt.setInt(1, Integer.parseInt(id));
pstmt.setObject(2, InetAddress.getByName(fromIP));
pstmt.setObject(3, InetAddress.getByName(toIP));
pstmt.execute();

我得到此语句 pstmt.setObject(2, InetAddress.getByName(fromIP)); 的异常;

org.postgresql.util.PSQLException:错误:inet 类型的输入语法无效:

请帮我解决这个异常

谢谢 --SD

【问题讨论】:

  • 我知道了,它的 pstmt.setObject(2, fromIP, Types.OTHERS);谢谢--SD

标签: java postgresql ip-address prepared-statement inet


【解决方案1】:

你现在已经找到它了,但是对于普通大众:

inet data type 接受 IPv4 和 IPv6 主机和网络,而不是域名。
作品:

SELECT '192.168.1.251'::inet
SELECT '123.45.67.89/32'::inet
SELECT '::ffff:10.4.3.2'::inet
SELECT '1234:ef8:345:ad:934:efff:aaa:d1f1/128'::inet

不起作用:

SELECT 'stackoverflow.com'::inet

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-11
    • 2018-09-29
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多