Re: [INTERFACES] New code for JDBC driver

Поиск
Список
Период
Сортировка
От Michael Stephenson
Тема Re: [INTERFACES] New code for JDBC driver
Дата
Msg-id Pine.LNX.4.30.0107111146480.14094-100000@tirin.openworld.co.uk
обсуждение исходный текст
Ответ на Re: [INTERFACES] New code for JDBC driver  ("Arsalan Zaidi" <azaidi@directi.com>)
Список pgsql-jdbc
> I agree that it probably is. Unfortunately, as I mentioned in my previous
> post,no one is going to be entering in SQL queries directly through our
> interface. We're not doing it and if someone is, he's up to no good. e.g.
>
> "update users set name='"+name+"'"
>
> If there's a text box in which you enter your name for the first query, I
> can some fun if I enter in
>
> Arsalan'';update funds set money = 100000 where userid =10
>
> Am I right? It's situations like these that I'm trying to prevent. Is there
> a better way?

If I'm not using prepared statements to tend to use something like:

String statement = "update users set name='" + encode(name) + "'";

Where encode is defined as:

/**
 * Encode a string suitable for being placed in a query.
 */
final String encode(String dirtyString) {
    StringBuffer cleanString = new StringBuffer("");
    for (int i = 0; i < dirtyString.length(); i++) {
    char c = dirtyString.charAt(i);
    cleanString.append(c);
    if (c == '\'') {
        cleanString.append(c);
    }
    }
    return cleanString.toString();
}

Hope this helps,

Michael Stephenson


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Steve SAUTETNER
Дата:
Сообщение: : SQLException.getErrorCode() : Where can I find list of error code and description ?
Следующее
От: Tony Grant
Дата:
Сообщение: JDBC and stored procedures