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
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
