Re: macaddr data type and prepared statements
От | Steve Foster |
---|---|
Тема | Re: macaddr data type and prepared statements |
Дата | |
Msg-id | 4898134D.8000102@leeds.ac.uk обсуждение исходный текст |
Ответ на | Re: macaddr data type and prepared statements (Oliver Jowett <oliver@opencloud.com>) |
Список | pgsql-jdbc |
Hi Folks, 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 >
В списке pgsql-jdbc по дате отправления: