Skip site navigation (1) Skip section navigation (2)

macaddr data type and prepared statements

From: Steve Foster <s(dot)p(dot)foster(at)leeds(dot)ac(dot)uk>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: macaddr data type and prepared statements
Date: 2008-08-04 13:28:34
Message-ID: 48970402.9080808@leeds.ac.uk (view raw or flat)
Thread:
Lists: pgsql-jdbc
Hi All,

I'm trying to bulk load some MAC addresses using a prepared statement. 
But I keep on getting an error about incorrect datatype (complains that 
I'm trying to insert "character varying").  Bellow is an example of the 
code that I'm using:

  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;
                }
            stmt.setDate(1, new java.sql.Date( 
dfmt.parse(line[0]).getTime()) );
            stmt.setDate(2, new java.sql.Date( 
tfmt.parse(line[1]).getTime()) );
            stmt.setString(3, line[2]);
            stmt.setString(4, line[3]);
            stmt.execute();
            }

            stmt.close();
}

Any recommendations?

Cheers

Steve

Responses

pgsql-jdbc by date

Next:From: Gustav TredeDate: 2008-08-04 13:53:29
Subject: Re: macaddr data type and prepared statements
Previous:From: Oliver JowettDate: 2008-08-02 08:56:40
Subject: Re: Encoding issues

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group