87,904
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" import="java.sql.*,java.io.*,java.util.*"%>
<%@ page contentType="text/html;charset=utf-8"%>
<head>
</head>
<body>
<script language="javaScript">
function checkAll(name) {
var si = document.getElementsByName('selecteditem');
for(var i=0; i<si.length; i++)
{
si[i].checked = !si[i].checked;
}
}
function clearAll(name) {
var si = document.getElementsByName('selecteditem');
for(var i=0; i<si.length; i++)
{
si[i].checked = false;
}
}
function chaxun() {
document.chaxun.action = "";
document.chaxun.submit();
}
function tijiao() {
document.chaxun.action = "servlet/peidang";
document.chaxun.submit();
}
</script>
<%
String driverName = "com.mysql.jdbc.Driver";
String userName = "user";
String userPasswd = "pwd";
String dbName = "testDB";
String tableName = "data_temp";
String url = "jdbc:mysql://localhost:3306/" + dbName + "?user="
+ userName + "&password=" + userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "select mo,item_id,item_name from "
+ tableName
+ " where item_id = '" + request.getParameter("item_id")
+ "'";
System.out.println("sql = " + sql);
ResultSet rs = statement.executeQuery(sql);
%>
<table>
<form name="chaxun" method="post" action="">
<tr align="left" width="400" height="50">
<td><a style="float:left" href="index.jsp" target="_top" onclick="return confirm('确认要返回吗?')">返回首页</a></td>
</tr>
<tr align="left" width="400" height="50">
<td width="250">请输入item_id : <font color="blue"></td>
<td>
<input type="text" name="item_id" style="width:150px;height:30px">
</td>
<td>
<input type="submit" value=" 确认 " style="width:100px;height:30px" onclick="chaxun()">
</td>
</tr>
</table>
<table>
<thead>
<tr align="center" height="50">
<td>
<span></span>
</td>
<td>
<span>mo</span>
</td>
<td>
<span>item_id</span>
</td>
<td>
<span>item_name</span>
</td>
</tr>
</thead>
<%
while (rs.next()) {
%>
<tbody>
<tr align="center" height="50">
<td width="overflow-x:auto" height="50">
<input type="checkbox" style="width:30px;height:30px" checked="checked" value="" name="selecteditem">
</td>
<td width="overflow-x:auto" height="50" id="mo">
<%
out.print(rs.getString(1));
%>
</td>
<td width="overflow-x:auto" height="50" id="item_id">
<%
out.print(rs.getString(2));
%>
</td>
<td width="overflow-x:auto" height="50" id="item_name">
<%
out.print(rs.getString(3));
%>
</td>
</tr>
</tbody>
<%
}
%>
</table>
<table bgcolor="#FFFFFF" border="0" cellspacing="0">
<tr align="center" width="400" height="50">
<td></td>
</tr>
</table>
<table bgcolor="#FFFFFF" border="0" cellspacing="0">
<tr align="center" width="400" height="50">
<td width="130">
<input type="button" value=" 全选 " style="width:100px;height:30px" onClick="checkAll('selecteditem')" id="qx">
</td>
<td width="130">
<input type="button" value=" 全选解除 " style="width:100px;height:30px" onClick="clearAll('selecteditem')" id="jc"">
</td>
<td width="140">
<input type="button" value=" 提交 " style="width:100px;height:30px" onClick="tijiao()" id="qr">
</td>
</tr>
</form>
</table>
</body>
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String[] mo= request.getParameterValues("selecteditem");
String updmo = "";
System.out.println("get mo : " +mo);
Connection conn = null;
String sql;
String url = "jdbc:mysql://localhost:3306/testDB?user=user&password=pwd";
response.setContentType("text/html");
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url);
for(int i= 0 ; i <mo.length ; i++ )
{
updmo+=mo[i]+"','";
System.out.println("updmo:"+updmo);
sql = "update data_temp set status = '1' where mo in ('"
+ updmo + "')";
System.out.println(sql);
PreparedStatement ps = conn.prepareStatement(sql);
ps.execute();
}
PrintWriter out = response.getWriter();
out.flush();
out.close();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}