Paul:
   I'am new at Java but, this insert works and maybe it will help you.  What
sql error are you getting?  Look up the SQL error and it will probably point
you in the right direction.  Here is an example of an insert I did and it's
catch.  It does work.  I am using javabeans which is how I get my values.

          String insert;
          try
          {
             Statement statement;
             statement = dbCon.createStatement();

        if (compldate == null)
                {
         insert = "INSERT INTO PROJECT.USER_RQST " +
                 "(REQUEST_NR, ACCOUNT_NUMBER, ACCOUNT_NAME, REQUESTOR_NAME,
" +
                 "REQUESTOR_INITIALS, PRIORITY_CODE, " +
                 "REQUESTOR_PHONE, REQUESTOR_EMAIL, REQUEST_TITLE,
REQUEST_DESC) " +
                 "values ('"+ requestno +"','"+ acctnr +"','" + acctnm
+"','"+ requestorname +"','"+ requestorinitials +"','" +
                          prioritycd + "','"+ requestorphone +"','"+
requestoremail +"','"+ requesttitle + "','" +
                                  requestdescrip +"')";
                }
                else
                {
                insert = "INSERT INTO PROJECT.USER_RQST " +
                "(REQUEST_NR, ACCOUNT_NUMBER, ACCOUNT_NAME, REQUESTOR_NAME,
" +
                "REQUESTOR_INITIALS, PRIORITY_CODE, COMPLETION_DATE, " +
                "REQUESTOR_PHONE, REQUESTOR_EMAIL, REQUEST_TITLE,
REQUEST_DESC) " +
                "values ('"+ requestno +"','"+ acctnr +"','" + acctnm
+"','"+ requestorname +"','"+ requestorinitials +"','" +
                         prioritycd + "','" + compldate + "','"+
requestorphone +"','"+ requestoremail +"','"+ requesttitle + "','" +
                          requestdescrip +"')";
                }

        statement.executeUpdate ( insert );
                statement.close();
          }
          catch ( SQLException sqlex ) {
             sqlex.printStackTrace();
           addErrorMsg ("SQL Error encountered." + sqlex.toString());
          }

Sandi


-----Original Message-----
From: Paul Foxton [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 04, 2001 11:43 AM
To: [EMAIL PROTECTED]
Subject: Re: SQL string


thanks John,

yes I tried that too.

I'm thinking I must have an error somewhere else now.

the servlet gets right up to: stmt.executeUpdate(sql);

and throws an exception.

Ho hum, back to the drawing board :)

-----Original Message-----
From: John Johnson [mailto:[EMAIL PROTECTED]]
Sent: 04 May 2001 17:47
To: [EMAIL PROTECTED]
Subject: Re: SQL string


Hi Paul,

Don't you need single quotes surrounding the values which you are
inserting??

for example:    INSERT INTO table (field1,field2) VALUES
('value1','value2')

Cheers,
  -john


Paul Foxton wrote:
>
> hopefully a simple one -
>
> can anyone tell me if theres anything wrong with this SQL string?
>
> INSERT INTO Customers (FirstName, LastName, Email, Phone, CompanyName)
> VALUES (wrtwrt, wrtw, wrtwrt, wrtwert, ertwrt)
>
> (all fields are text)
>
> heres the code that generates it:
>
> String sql = "INSERT INTO Customers (" +
>                          "FirstName, LastName, Email, Phone, CompanyName)
"
> +
>                          "VALUES (" + req.getParameter("fname") + ", " +
>                                     req.getParameter("lname") + ", " +
>                                     req.getParameter("email") + ", " +
>                                     req.getParameter("phone") + ", " +
>                                     req.getParameter("company") + ")";
>
> for some reason the update isn't working, just want to check theres
nothing
> wrong with the sring.
>
> I'm accessing an access db via ODBC, I'm getting a connection to the db
ok.
>
> thanks,
>
> Paul
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

--
John Johnson
Software Engineer
Supply Chain Logic, Inc.
301-210-7400, x217

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to