shoutsound_delectdata.java 2.1 KB
package com.servlet.bksh.DMC;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.dbutil.DataBase;

public class shoutsound_delectdata extends HttpServlet {
	private static final String DB_URL = "db_bk_cxwsjh";
	int update = 0;
	Connection conn = null;
	Statement statement = null;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String results = request.getParameter("results");
		int id = Integer.valueOf(results);
		String sql = "DELETE FROM t_shsound WHERE id='" + id + "'";
		if (id > 0) {
			try {
				conn = DataBase.getConnection(DB_URL);
				statement = conn.createStatement();
				update = statement.executeUpdate(sql);
				System.out.print(update);
				PrintWriter out = response.getWriter();
				if (update == 1) {
					out.write("sucess");

				} else {
					out.write("error");
				}
				out.close();
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				if (update == 0) {
					System.out.print("库执行失败sql:" + sql);
				}
				System.out.print("库的sql以及执行结果:" + sql + " is result=" + update);
				if (null != conn) {
					try {
						conn.close();
					} catch (Exception e) {
						System.out.print("关闭数据库连接出错");
					}
				}
				if (null != statement) {
					try {
						statement.close();
					} catch (Exception e) {
						System.out.print("关闭数据库连接出错");
					}
				}
			}
		}
	}

}