mysqlservlet
这是更新的函数,在productdaoimpl类里:
public int updateProduct(Product product){
int flag = 0;
DBConnect conn = null;
PreparedStatement pstmt = null;
<code>//update statement String sql = "update productinfo set productnumber=?,productvalue=? where productname=?"; try {//connect DB conn = new DBConnect() ; pstmt = conn.getConnection().prepareStatement(sql) ; pstmt.setString(1, product.getProductnumber()); pstmt.setString(2, product.getProductvalue()); pstmt.setString(3, product.getProductname());//update pstmt.executeUpdate(); flag = 1; pstmt.close(); } catch (Exception e) { e.printStackTrace(); } finally { conn.close(); } return flag;</code>
}
updateServlet的代码:
package jspservlet.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jspservlet.dao.ProductDAO;
import jspservlet.dao.impl.ProductDAOImpl;
import jspservlet.vo.Product;
public class ProductUpdateServlet extends HttpServlet {
<code> public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ this.doPost(req, res); } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ Product product = new Product(); product.setProductname(req.getParameter("productname")); ProductDAO dao=new ProductDAOImpl(); int flag = 0; int flag2 = 1; try { flag2 = dao.queryByProductName(product); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (flag2 == 1) { res.sendRedirect("./errorRegister.jsp"); } else { try { flag = dao.updateProduct(product); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if( flag == 1) { //session是干嘛的? HttpSession session = req.getSession(); session.setAttribute("productname", product.getProductname()); res.sendRedirect("./success.jsp"); } else { res.sendRedirect("./error.jsp"); } } } </code>
}
JSP页面:
Delete Product
the name of the product you want to update:
<code> <form method="post" action="./update"> productname : <input type="text" name="productname"><br> <p>the number and price of the product you want to change to:</p> productnumber : <input type="text" name="productnumber"><br> productvalue : <input type="text" name="productvalue"><br> <input type="SUBMIT" name="submit" value="Submit"> </form></code>

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft