How to connect database using html,bean,jsp....

Hi Developers.......... This is basic, but i don't now.I have login form.The colums is username,password.To test these to connect database and check those.and forward to inserted sucessfully.Any body help me in this please..with regardssure...:)-
[275 byte] By [sure_2912a] at [2007-10-3 0:00:29]
# 1

set action of the jsp form to a servlet name eg ....action ="myservlet"

In the post/get method of myservlet,

get the data from the jsp using

the method getParameter("paramName").

Connect to the bean and set these values (Can use jndi for cmp)

the bean connects to the dbase

if no exceptions are thrown, forwad to success jsp

Use req.getRequestDispatcher("/successJSP").include(req, resp);

If you need to use the bean in successJSP set it as an attribute for req

and access it in the jsp using getAttribute("attrName")

r035198xa at 2007-7-14 16:47:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi friend, please send examples...with regardssure...:)-
sure_2912a at 2007-7-14 16:47:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

well first you need to configure a driver to conect with the database, i use the jdbc-odbc so i need first to configure an ODBC of the database, i use only jsp not beens:

first i get the username and the password from a form and save the data in session in orde to remmember for another operations

<%

String identificador = request.getParameter("id");

String clave = request.getParameter("clve");

session.setAttribute("nom",identificador);

session.setAttribute("clve",clave);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url = "jdbc:odbc:local1";

Connection con = DriverManager.getConnection(url, identificador, clave);

String Agente = request.getHeader("User-Agent");

String Host = request.getRemoteHost();

Statement stmt = con.createStatement();

stmt.executeUpdate("insert into visitas values (" + fecha + "," + "'" + hora + "'" + "," + "'" + Agente + "'" + "," + "'" + Host + "'" + ")");

ResultSet rs = stmt.executeQuery("select count (*) from visitas");

rs.next();

String num = rs.getString(1);

out.println(num);

?>

this code connect to the database with user and password given in another page (post action) and insert into a table information like date, hour, etc...

sorry for my english...

eckoa at 2007-7-14 16:47:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Hi friend ...Thanks for your response.I know this procedure.I want code with using bean implimetation .If you have that code please send. I am waiting for your response.with regardsyour's sure....:)-
sure_2912a at 2007-7-14 16:47:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...