Обсуждение: INSERT query (using insert from a Java application, concerning String input)

Поиск
Список
Период
Сортировка

INSERT query (using insert from a Java application, concerning String input)

От
Atika
Дата:
HI!!
I am hoping someone can help me with a problem I have.

I am trying to insert values in my pgsql database through a Java
application.
The problem is that I need to insert a String into a table.  But, as I am
not going to know the value of this String before hand I can't really put
a value within two single qoutes.
I am basically trying to do something like this:

String input = "This is a String";

myConn.updateQuery("insert into myDB values(input)");

but get an error when I  run it saying:
ERROR:  attribute input not found
java.sql.SQLException: ERROR:  attribute input not found

I am also going to have to insert integer and other such values but am not
going to know their values when I use the insert statement.

many thanks for your time and help.


Re: [SQL] INSERT query (using insert from a Java application, concerning String input)

От
"Brett W. McCoy"
Дата:
On Wed, 17 Feb 1999, Atika wrote:

> String input = "This is a String";
>
> myConn.updateQuery("insert into myDB values(input)");
>
> but get an error when I  run it saying:
> ERROR:  attribute input not found
> java.sql.SQLException: ERROR:  attribute input not found
>
> I am also going to have to insert integer and other such values but am not
> going to know their values when I use the insert statement.

I don't know the details of the Java interface (perhaps you should pose
your question to the interfaces list?), but you still need the single
quotes else the term ends up in the SQL querytree as an attribute rather
than as data to insert into an attribute.  All of the language interfaces
I have used still require the single quotes, even if you are
interpolating string variables inside of the SQL statement.  Or is the
JDBC completely different in this?  Can you prepare your query string
beforehand and then pass the entire string as a varaible rather than as
a literal to the updateQuery method?

Brett W. McCoy
                                         http://www.lan2wan.com/~bmccoy
-----------------------------------------------------------------------
Labor, n.:
    One of the processes by which A acquires property for B.
        -- Ambrose Bierce, "The Devil's Dictionary"

----- BEGIN GEEK CODE BLOCK -----
Version: 3.12
GAT dpu s:-- a C++++ UL++++$ P+ L+++ E W++ N- o K- w--- O@ M-@ !V PS+++
PE Y+ PGP- t++ 5- X+ R+@ tv b+++ DI+++ D+ e>++ h+ r++ y++++
------ END GEEK CODE BLOCK ------