error coding the following(inserting data from jsp to mysql database)
807598Apr 3 2006 — edited Apr 7 2006hi,
i am writing a code so that when i register it should be added to the register database.
i have made a table called register.(three columns loginid,password,email)
have created connection using jdbc:mysql driver.
have added jstl library and mysql connector ver 3.XXX.jar
all i want is that when i run my register.html, register in then the register .jsp should be able to store the new values in the register table . this happens when i click the submit button in register.html, which takes me to register.jsp.
i have written the following code in register.jsp
what is wrong , and what should i do ? kindly help
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
import java.sql.*;
public class insertTableData
{
public static void main(String[] args)
{
DB db = new DB();
Connection conn=db.dbConnect(
""jdbc:mysql://localhost:3306/register","root","password");
db.insertData(conn);
}
}
class DB
{
public DB() {}
public Connection dbConnect(String db_connect_string,
String db_userid,String db_password)
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string,db_userid,db_password);
System.out.println("connected");
return conn;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public void insertData(Connection conn)
{
Statement stmt;
try
{
stmt = conn.createStatement();
stmt.executeUpdate("insert into register " +
"values('loginid', 'password','email')");
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">
<!-- Let's welcome the user ${param.name} -->
Hello ${param.name}!
</c:if>
--%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jsp</title>
<style type="text/css">
</body>
</html>
error:
the code is displayed at is when i click the submit button. ie the register.jsp shows the code as it is.
what steps should i follow to remove the error and do what i want to.
cheers