gpt4 book ai didi

java.lang.AbstractMethodError : com. mysql.jdbc.PreparedStatement.setBlob(ILjava/io/InputStream;)V

转载 作者:行者123 更新时间:2023-11-29 02:00:38 25 4
gpt4 key购买 nike

<分区>

我正在尝试将上传的文件保存在 MySQL 数据库中,如下所示:

String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");

InputStream inputStream = null; // input stream of the upload file

// obtains the upload file part in this multipart request
Part filePart = request.getPart("photo");
if (filePart != null) {
// prints out some information for debugging
System.out.println(filePart.getName());
System.out.println(filePart.getSize());
System.out.println(filePart.getContentType());

// obtains input stream of the upload file
inputStream = filePart.getInputStream();
}

Connection conn = null; // connection to the database
String message = null; // message will be sent back to client

try {
// connects to the database
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn = DriverManager.getConnection(dbURL, dbUser, dbPass);

// constructs SQL statement
String sql = "INSERT INTO image(image,firstName, lastName) values (?, ?, ?)";
PreparedStatement statement = conn.prepareStatement(sql);

if (inputStream != null) {
// fetches input stream of the upload file for the blob column
statement.setBlob(1, inputStream);
}

statement.setString(2, firstName);
statement.setString(3, lastName);

// sends the statement to the database server
int row = statement.executeUpdate();
if (row > 0) {
message = "File uploaded and saved into database";
}
} catch (SQLException ex) {
message = "ERROR: " + ex.getMessage();
ex.printStackTrace();
} finally {
if (conn != null) {
// closes the database connection
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
// sets the message in request scope
request.setAttribute("Message", message);

// forwards to the message page
getServletContext().getRequestDispatcher("/Message.jsp").forward(request, response);
}

当我运行它时,我得到一个错误:

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setBlob(ILjava/io/InputStream;)V
UploadServlet.doPost(UploadServlet.java:64)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

这个错误可能是什么原因?输入字段名称是 firstName、lastName 和 photo

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com