HI,
I want a simple jsp script which takes in value from user
through a form and store it in database.

I wrote the followwing code :

form.jsp :::




Forms



Enter in a website name:



Enter the id:








This calls the form confirm.jsp :

<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.sql.*" %>




confirm



Your info has been received:




<%

String queryText = "INSERT INTO mytab VALUES( \""+
request.getParameter("name") + "\" , request.getParameter("id") )";

try {
Statement stmt;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test";
Connection con = DriverManager.getConnection(url,"root", "root");
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeUpdate(queryText);

}
catch (Exception e) { }
con.close();

response.sendRedirect("first.jsp");

%>