jsp error plz check this code why are not insert my data into database

Posted by lekhni on Stack Overflow See other posts from Stack Overflow or by lekhni
Published on 2010-06-09T12:40:22Z Indexed on 2010/06/09 12:42 UTC
Read the original article Hit count: 203

Filed under:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*"%>

<%@ page import="java.io.File"%>

<%@ page import="java.util.*"%>

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

<%@ page import="java.sql.Blob"%>

<%@ page import="java.sql.PreparedStatement"%>

<%@ page import="java.sql.BatchUpdateException"%>

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

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

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'p.jsp' starting page</title>

 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">    
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>

  <body>
    <% 

int activityId = Integer.parseInt(request.getParameter("activityId"));
String name = request.getParameter("name");
String activityType = request.getParameter("activityType");
int parentId = Integer.parseInt(request.getParameter("parentId"));
String description = request.getParameter("description");
%>
 <%
Connection conn=null;
PreparedStatement pstatement = null;
 try{
 Class.forName("com.mysql.jdbc.Driver");
 conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/pol","root","1234");
 Statement st=conn.createStatement();

String queryString = "INSERT INTO activity(activityId,name,activityType,parentId,description)" + " VALUES (?, ?, ?, ?, ?)";

 pstatement = conn.prepareStatement(queryString);

pstatement.setInt(1, activityId);
pstatement.setString(2, name);
pstatement.setString(3, activityType);
pstatement.setInt(4, parentId);
pstatement.setString(5, description);

 }
catch (Exception ex) {
   out.println("Unable to connect to batabase.");
}

finally {
pstatement.close();
conn.close();

}

%>

  </body>
</html>

© Stack Overflow or respective owner

Related posts about jsp