<%@ 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");
%>开发者_如何学C;
<%
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>
You never call pstatement.executeUpdate();
?
You are missing execute update: ps.executeUpdate();
精彩评论