OK Think I've got it sorted... At least I'm inserting using a prepared
statement, the following worked fine. Anyone got any suggestions as to
why I shouldn't do it this way, it feels right but its too simple so I'm
being cautious.
Cheers
Steve
----Code----
org.postgresql.util.PGobject MACADDR = new org.postgresql.util.PGobject();
MACADDR.setType("macaddr");
org.postgresql.util.PGobject CIDR = new org.postgresql.util.PGobject();
CIDR.setType("cidr");
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(jdbc_url, jdbc_user,
jdbc_pass);
PreparedStatement stmt = conn.prepareStatement("insert into
log (date, time, mac, network) values (?,?,?,?)");
while (inputLineIterator.hasNext()) {
String[] line = inputLineIterator.next();
if (line == null) {
continue;
}
MACADDR.setValue(line[2]);
CIDR.setValue(line[3]);
stmt.setDate(1, new java.sql.Date(
dfmt.parse(line[0]).getTime()) );
stmt.setTime(2, new java.sql.Time(
tfmt.parse(line[1]).getTime()) );
stmt.setObject(3, MACADDR);
stmt.setString(4, CIDR);
stmt.execute();
}
stmt.close();
}
----Code----
Oliver Jowett wrote:
> Dave Cramer wrote:
>
>> You can extend PGobject to create a PGMacaddr object to get it to
>> work with prepared statements
>
> Or you can put an explicit cast in your insert statement.
>
> -O
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
No comments:
Post a Comment