我想将图片上传到数据库但我遇到了问题。这是我的代码, Pojo类
login.php
BL经理
login.php
Servlet文件
public class Pojo {
String fnm;
String lnm;
InputStream b;
public String getFnm() {
return fnm;
}
public void setFnm(String fnm) {
this.fnm = fnm;
}
public String getLnm() {
return lnm;
}
public void setLnm(String lnm) {
this.lnm = lnm;
}
public InputStream getB() {
return b;
}
public void setB(InputStream b) {
this.b = b;
}
}
数据库连接文件......
public class BusinessLogic {
public boolean insert(Pojo bean)
{
boolean check_connection=false;
try
{
System.out.println("inside Registration");
Connection conn= (Connection) DBConnection.connect();
String sql = "INSERT INTO image1 (first_name, last_name, photo) values (?, ?, ?)";
PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
ps.setString(1,bean.getFnm());
ps.setString(2,bean.getLnm());
ps.setBlob(3, bean.getB());
ps.executeUpdate();
check_connection =true;
conn.close();
}
catch(Exception e)
{
System.out.println(""+e);
}
return check_connection;
}
}
当我尝试将图像插入数据库时,它给出了以下错误:
java.lang.AbstractMethodError:Method com / mysql / jdbc / PreparedStatement.setBlob(ILjava / io / InputStream;)V是 摘要 com.mysql.jdbc.PreparedStatement.setBlob(PreparedStatement.java)at at com.image.model.BusinessLogic.insert(BusinessLogic.java:22)
请帮我解决这个问题...
答案 0 :(得分:0)
名为cos.jar的JAR文件包含com.oreilly.servlet和com.oreilly.servlet.multipart包。这些包包括几个类,例如以“Multipart”开头的所有Java类,它们可用于处理servlet中的文件上载。你可以找到它的jar,它很容易集成。
MultipartRequest m=new MultipartRequest(request,"d:/new");
out.print("successfully uploaded");