Servlet???????? ??????Mysql?????
???????????? ???????[ 2016/9/12 10:24:21 ] ????????????? MySQL
??????????? ?????????? Servlet?????? ?????????? ??????? ?????? ????????? ?????????? ???connection???? ?д????????????????? ????preparedStatement ???
????package Servlet;
????import java.io.IOException;
????import java.io.InputStream;
????import java.sql.Connection;
????import java.sql.DriverManager;
????import java.sql.PreparedStatement;
????import javax.servlet.ServletException;
????import javax.servlet.http.HttpServlet;
????import javax.servlet.http.HttpServletRequest;
????import javax.servlet.http.HttpServletResponse;
????import org.apache.commons.fileupload.FileItemIterator;
????import org.apache.commons.fileupload.disk.DiskFileItemFactory;
????import org.apache.commons.fileupload.servlet.ServletFileUpload;
????/**
????* Servlet implementation class ImageServlet
????*/
????public class ImageServlet extends HttpServlet {
????private static final long serialVersionUID = 1L;
????protected void doPost(HttpServletRequest request?? HttpServletResponse response) throws ServletException?? IOException {
????// TODO Auto-generated method stub
????System.out.println(123);
????try {
????DiskFileItemFactory factory = new DiskFileItemFactory();
????ServletFileUpload upload = new ServletFileUpload(factory);
????FileItemIterator iter = upload.getItemIterator(request);
????InputStream inputStream = iter.next().openStream();
????Class.forName("com.mysql.jdbc.Driver");
????Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Demos"??"root"??"1a");
????String sql = "insert into image_Demo(image) values (?)";
????PreparedStatement ps = conn.prepareStatement(sql);
????ps.setBinaryStream(1?? inputStream?? inputStream.available());
????ps.execute();
????} catch (Exception e) {
????// TODO Auto-generated catch block
????e.printStackTrace();
????}
????}
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11