Using a form to submit data to database

I have a servlet and I am trying to implement a form in the page so that it will submit from a text box a string into the database. Here is my code.

java.util.Date d = new java.util.Date();

java.sql.Timestamp t = new java.sql.Timestamp(d.getTime());

String data = "";

out.println("<form method=get>");

out.println("Enter Data: ");

out.println("<input type=text name='data' >");

out.println("<input type=submit value=Submit>");

out.println("</form>");

// Insert Data

PreparedStatement pst = con.prepareStatement("INSERT INTO FOO (NAME,DATE_MODIFIED) VALUES(?,?)");

pst.setString(1, data);

pst.setTimestamp(2, t);

pst.executeUpdate();

I believe this is incorrect in the <form> code. I do not know how to INSERT the data that is submitted from the <form>.

[888 byte] By [dUb] at [2007-9-26 3:18:32]
# 1

You need to separate the servlet code from the HTML code.

First you create an HTML page with the HTML form:

<form method="get" ACTION="myservletname">

Enter Data:

<input type=text name='data' >

<input type=submit value=Submit>

</form>

Then you create the servlet which will read the request object with the parameter called "data".

And then you input that value into a database.

Visit the servlet tutorials in the Sun site.

-AJD

ajdiaz at 2007-6-29 11:32:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
How do I pass the 'data' string to my servlet? What method is used?
dUb at 2007-6-29 11:32:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...