update.jsp

来自「use eclipse+js platform impement tree me」· JSP 代码 · 共 75 行

JSP
75
字号

<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=gb2312"  %>
<%
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 'update.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>
   <%
   try{
  request.setCharacterEncoding("gbk");
  
 String parent=request.getParameter("parent1");
 String child1=request.getParameter("child1");
 String child2=request.getParameter("child2");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+"C:\\Documents and Settings\\Administrator\\My Documents\\"+"menu.mdb";
Connection conn = DriverManager.getConnection(url); 
  if(parent.equals("根目录")){

  String sql1="update b set c_name='"+child2+"' where c_name='"+child1+"'";

  Statement statement = conn.createStatement();
  int i=statement.executeUpdate(sql1);
   if(i==0) out.print("修改不成功");
 else out.print("修改成功");
  statement.close();
 }
 else {
 String sql2="select c_id from b where c_name='"+parent+"'";

 Statement stmt=conn.createStatement();
 ResultSet rs=stmt.executeQuery(sql2);
 int paren=0;
 if(rs!=null){
 if(rs.next()) {paren=rs.getInt(1);
 

 stmt.close();
 String sql="update c set c1_name='"+child2+"' where c1_name='"+child1+"' and c_id="+paren+"";

	Statement statement = conn.createStatement();		
	int i=statement.executeUpdate(sql);
 if(i==0) out.print("修改不成功");
 else out.print("修改成功");
 statement.close();
 conn.close();
}
else out.print("修改不成功");
}}
}catch(Exception e){
out.print(e.getMessage());}
  
 %>
  </body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?