UnicodeError: ASCII decoding error: ordinal not in range(128)

Gerhard Häring gerhard.haering at gmx.de
Sat Jul 20 09:50:52 EDT 2002


eugene kim wrote in comp.lang.python:
> thx again..
> 
> i got PyGreSQL(pyPgSQL gave me error ImportError: No module named libpq)
> i looked at 
>>>>help(pgdb)
> that was about all docs i could get including from web
> 
> python looks really clean(<->perl), and requires a lot less coding(<->java)
> so i'm trying to learn python..

I agree that DB programming in Python generally works with less code
than in Java.

> by the way
> 
> my last question about java was..
> is this form below also available in java?
> ---------------------------
> cursor.execute("insert into history (col1, col1, col3) values (%s, %s, %s)",
>>                  (self.url, self.title, self.firsttime))

Well, this is normally off-topic here, but here goes an example for
this in Java:

import java.sql.*;

/* Minimal JDBC example, no error checking for brevity */
public class pgjdbcex {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String url = "http://www.postgresql.org";
        String title = "PostgreSQL";
        int firsttime = 42;

        // Load driver
        Class.forName("org.postgresql.Driver");
        
        // Get connection
        Connection db = DriverManager.getConnection("jdbc:postgresql://gargamel/gerhard", "gerhard", "sicrit");

        // Get a prepared statement
        PreparedStatement pst = db.prepareStatement("insert into history (col1, col2, col3) values (?, ?, ?)");

        // bind parameters
        pst.setString(1, url);
        pst.setString(2, title);
        pst.setInt(3, firsttime);

        // execute
        pst.executeUpdate();

        pst.close();
        db.close();
    }
}

so you can see that the

> cursor.execute("insert into history (col1, col1, col3) values (%s, %s, %s)",
>                  (self.url, self.title, self.firsttime))

expands to four statements in Java.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



More information about the Python-list mailing list