0

I am trying to migrate my java application from PostgreSQL 8.4 to latest release. I am facing an issue with reading the byte data from the db. I am inserting the IpAddress in bytes in to the table and trying to reconstruct it back in a different process. but while reconstruction i could see and extra '/' character here is what exactly i am doing.

stat = con.prepareStatement("insert into IPADDR(IP_ADDR, LSVR_ID) values(?, ?)");
InetAddress iaddr = InetAddress.getLoopbackAddress();
            stat.setBytes(1, iaddr.getAddress());
            stat.setInt(2, ID);
            stat.executeUpdate();

and read it back like this

stat = con.prepareStatement("select IP_ADDR  from IPADDR");

when i print the bytes before inserting and after retrieval i could see that they are not same. for local loopback address which is 127.0.0.1 before inserting its "[B@106bdde4" however the one got from DB looks like [B@6d7eaa83 when i construct string out of it it shows additional '/' character ==>"/127.0.0.1" can anyone please help in resolving this issue

pes502
  • 1,597
  • 3
  • 17
  • 32
HSK
  • 55
  • 4
  • Why are you using `setBytes` to set the IP address in the prepared statement? – Craig Ringer Jul 01 '14 at 07:50
  • What is the datatype of the column `ip_addr`? –  Jul 01 '14 at 07:52
  • code Ipaddress.getaddress() would return bytearray itself. as this is a legacy application Don't have much control over it to change. ip_addr column has a type bytea. – HSK Jul 01 '14 at 07:53

0 Answers0