📄 post.jsp
字号:
<%@page contentType="text/html; charset=gb2312" language = "java"%>
<%@page import = "java.sql.*"%>
<%request.setCharacterEncoding("gb2312");%>
<%!
String strSql;
Connection conn;
Statement stmt;
/*
PreparedStatement pstmt;
*/
ResultSet result;
String commandstr;
String opt;
int id;
String rsName;
String rsContent;
%>
<%
opt = request.getParameter("opt");
if(request.getParameter("id") != null && !request.getParameter("id").equals("")){
id = Integer.parseInt(request.getParameter("id"));
}
rsName = request.getParameter("rsName");
rsContent = request.getParameter("rsContent");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:quchch","sa","");
stmt = conn.createStatement();
if(opt.equals("insert")){
commandstr = "Insert into tab(name,content) values('" + rsName + "','" + rsContent + "')";
/*
commandstr = "Insert into tab(name,content) values(?,?)";
pstmt = conn.prepareStatement(commandstr);
pstmt.setString(1,rsName);
pstmt.setString(2,rsContent);
*/
}else if(opt.equals("update")){
commandstr = "Update tab set name='" + rsName + "',content='" + rsContent + "' where id=" + id;
/*
commandstr = "Update tab set name=?,content=? where id=?";
pstmt = conn.prepareStatement(commandstr);
pstmt.setString(1,rsName);
pstmt.setString(2,rsContent);
pstmt.setInt(3,id);
*/
}else if(opt.equals("delete")){
commandstr = "delete from tab where id = " + id;
/*
commandstr = "delete from tab where id = ?";
pstmt = conn.prepareStatement(commandstr);
pstmt.setInt(1,id);
*/
}
stmt.executeUpdate(commandstr);
stmt.close();
/*
pstmt.executeUpdate();
pstmt.close();
*/
conn.close();
response.sendRedirect("list.jsp");
}catch(Exception e){
out.println(e);
}finally{
if(conn!=null){
conn.close();
}
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -