java执行多条sql命令
我现在在做一个留言板的注册页面,使用java做的,注册功能已经实现了,就是先在数据库中创建一个表,向里面添加注册信息,但我现在又想在有人注册的时候,每注册一个人就在数据库中创建一个专属于他的表,用来存储别人给他的留言主题和内容,这个该怎么实现?请高手指教,实现那个功能要在什么地方加什么代码,万谢!以下是代码:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String driver="org.postgresql.Driver";
String url="jdbc:postgresql://localhost:5432/guest";
String sql="insert into login(name,password,birthday,sex,hobby,phone) values(?,?,?,?,?,?)";
int result = 0;
Connection conn = null;
PreparedStatement pstmt = null;
String hobby = "";
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("utf-8");
out.println("<HTML>");
out.println(" <HEAD><TITLE>注册信息页面</TITLE></HEAD>");
out.println(" <BODY>");
if(StringUtil.validateNull(request.getParameter("name"))){
out.println("对不起,姓名不能为空,请重新输入!");
out.println("<a href='/liuyanban2/survey.htm'>重新添加注册内容</a><br>");
}else if(StringUtil.validateNull(request.getParameter("password"))){
out.println("对不起,密码不能为空,请重新输入!");
out.println("<a href='/liuyanban2/survey.htm'>重新添加注册内容</a><br>");
}else if(StringUtil.validateNull(request.getParameter("email"))){
out.println("对不起,Email不能为空,请重新输入!");
out.println("<a href='/liuyanban2/survey.htm'>重新添加注册内容</a><br>");
}else if(StringUtil.validateNull(request.getParameter("phone"))){
out.println("对不起,电话不能为空,请重新输入!");
out.println("<a href='/liuyanban2/survey.htm'>重新添加注册内容</a><br>");
}else {
try {
//conn=postchi.pgpool.getConnection();
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url,"postgres","123456");
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, StringUtil.filterHtml(request.getParameter("name")));
pstmt.setString(2, StringUtil.filterHtml(request.getParameter("password")));
pstmt.setString(3, request.getParameter("birthday1")+"年"+request.getParameter("birthday2")+"月"+request.getParameter("birthday3")+"日");
pstmt.setString(4, request.getParameter("sex"));
String[] hobbys = request.getParameterValues("hobby");
for(int i=0;i<hobbys.length;i++){
hobby+=hobbys[i];
}
pstmt.setString(5, hobby);
pstmt.setString(6, StringUtil.filterHtml(request.getParameter("phone")));
pstmt.setString(7, StringUtil.filterHtml(request.getParameter("email")));
result=pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if(result==0){
out.println("对不起,注册不成功!请重新注册");
out.println("<a href='/liuyanban2/survey.htm'>重新添加注册内容</a>");
}else{
out.println("恭喜!注册成功!查看注册信息"+"<br>"+"<br>");
out.println("<a href='/liuyanban2/denglu.htm'>登录</a>");
}
out.println("</body>");
out.println("</html>");
out.flush();
out.close();
}
}
}