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

时间:2012-03-16 17:25:09

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

我正在尝试从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

1 个答案:

答案 0 :(得分: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