I'm not quite clear on what you're after here, however at the risk of being
simplistic,
The SQL to insert value1 - 3 into field 1 -3 of table tblname would be:
INSERT into tblname (field1, field2, field3) VALUES (value1, value2, value3)

The JSP to execute would be:

          /* create and execute a statement */
          st=dbc.createStatement();
          sql=("INSERT into tblname (field1, field2, field3) VALUES (value1,
value2, value3)");
          st.executeUpdate(sql);

        ie: use executeUpdate() instead of executeQuery();

        Hope that helps


Tref Gare
Web Developer MCSD/SCJP
eCommerce Group
Phone:  (03) 9221 4106
Mobile: 0409 556 478
Fax:    (03) 9941 4295

> -----Original Message-----
> From: Graeme McLaren [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday,16 April 2002 8:50
> To:   [EMAIL PROTECTED]
> Subject:      JSPs/DBs and HTML Forms
>
> Hi everyone, I'm completely new to JSPs and I'm finding a somewhat
> daunting
> area.  Specifically I'm having a problem inserting information from an
> html
> form to a database using a JSP.
>
> Basically I've got the problem of getting the parameter and the value from
> the form then inserting it in to the database with SQL.
>
> I can use  mystring=request.getParameter("TheNameOfTheFormInput");  to get
> the value from the form elements.  Once I've done this I'm completely lost
> as to how to write the SQL to insert the values from the form elements
> INTO
> the database.
>
> Can anyone guide me through this, point me in the right direction or give
> me
> any tips at all.  Any advice would be greatly appreciated.
>
> Thank you in advance,
>
> Graeme :)
>
> P.S. Currently I've got a JSP like this:
>
> <!-- imports the JDBC functions -->
> <%@ page import="java.sql.*" %>
> <html>
> <head>
> <title>JDBC Example</title>
> </head>
> <body>
> <h1>JDBC with JSP</h1>
> <%
> /* various variable declarations */
> Connection dbc;
> Statement st;
> String sql;
> ResultSet rs;
> ResultSetMetaData rsmd;
>
> try {
>   /* load JDBC driver for PostgreSQL database */
>   Class.forName("postgresql.Driver");
>
>   /* make a connection to the database */
>
> dbc=DriverManager.getConnection("jdbc:postgresql://localhost/webtest","www
> -d
> ata","");
>
>   /* create and execute a statement */
>   st=dbc.createStatement();
>   sql=("SELECT * FROM example");
>   st.executeQuery(sql);
>
>   /* get the results and metadata */
>   rs=st.getResultSet();
>   rsmd=rs.getMetaData();
>
>   /* how many columns are there? */
>   int numcols=rsmd.getColumnCount();
>
>   /* start table and print headings */
>   out.println("<table>\n<thead>\n<tr>");
>   int i;
>   for (i=1;i<=numcols;i++)
>     out.print("<th>"+rsmd.getColumnLabel(i)+"</th>");
>   out.println("</tr>\n</thead>\n<tbody>");
>
>   /* print the rows of the table */
>   while (rs.next()) {
>     out.print("<tr>");
>     for (i=1;i<=numcols;i++)
>       out.print("<td>"+rs.getObject(i)+"</td>");
>     out.print("</tr>");
>     }
>
>   /* end table and close DB */
>   out.print("</tbody>\n</table>\n");
>   dbc.close();
>
>   /* error handling */
>   } catch (Exception e) {
>     out.println("<p>Error in JDBC database access</p>");
>     out.println("<p>"+e+"</p>");
>   } ;
>
> %>
> </body>
> </html>
>
> Thanks again,
>
> G :)
>
> Public Sub House()
>
> On Error Resume drink
>
>          If PintGlass.empty = True Then
>                  PintGlass.refill
>    Else
>                  PintGlass.drink
>          End if
>
> stomach.add PintGlass
>
> MsgBox " I've had .... " & stomach.count & " Pints"
> MsgBox "VERY DRUNK"
>
> End Sub
>
>
> _________________________________________________________________
> Join the world's largest e-mail service with MSN Hotmail.
> http://www.hotmail.com
>
> ==========================================================================
> =
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to