• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mapping an InetAddress to a Postgresql inet value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mapping an InetAddress to a Postgresql inet value


  • Subject: Re: Mapping an InetAddress to a Postgresql inet value
  • From: Miguel Arroz <email@hidden>
  • Date: Sun, 23 Dec 2007 19:44:23 +0000

Hi!

On 2007/12/23, at 19:35, Francis Labrie wrote:

Unfortunately, you can't convert this "inet" datatype diretly to "java.net.InetAddress" Java class, because the PostgreSQL datatype holds the netmask as well, unlike the Java class (read this thread: <http://osdir.com/ml/db.postgresql.jdbc/2003-12/msg00031.html>).

But you can create a custom class to manage this easily. For the example below, you just have to bound factory method to "valueOf" and conversion method to "toString":

I ended up doing a similar solution, but in the opposite direction: using the InetAddress class and dump it in binary to the DB:


import java.net.InetAddress;
import java.net.UnknownHostException;

import com.webobjects.foundation.NSData;


public class MyInetAddress { private InetAddress address; private MyInetAddress() { } public static MyInetAddress fromString( String theString ) { try { MyInetAddress result = new MyInetAddress(); result.setAddress(InetAddress.getByName( theString )); return result; } catch (UnknownHostException e) { throw new RuntimeException("Error creating address", e); } } public static MyInetAddress fromBinary( NSData data ) { try { MyInetAddress result = new MyInetAddress(); result.setAddress(InetAddress.getByAddress(data.bytes())); return result; } catch (UnknownHostException e) { throw new RuntimeException("Error creating address", e); } } public NSData toBinary() { return new NSData(address.getAddress()); } private void setAddress( InetAddress addr ) { address = addr; } public InetAddress address() { return address; } }


Kind regards, and Boas Festas e um feliz Ano Novo!

Obrigado! :)

  Yours

Miguel Arroz

Miguel Arroz
http://www.terminalapp.net
http://www.ipragma.com



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Mapping an InetAddress to a Postgresql inet value (From: Miguel Arroz <email@hidden>)
 >Re: Mapping an InetAddress to a Postgresql inet value (From: Francis Labrie <email@hidden>)

  • Prev by Date: Re: Mapping an InetAddress to a Postgresql inet value
  • Next by Date: Re: Thick as a Brick
  • Previous by thread: Re: Mapping an InetAddress to a Postgresql inet value
  • Next by thread: Re: valid global ID could not be obtained for entity
  • Index(es):
    • Date
    • Thread