A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

package a1;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Test {
public static void main(String[] args) {
  FileInputStream fis=null;
  //用MYSQL存一个BLOB类型存不进去,换了个longblob就好了,为什么?
  try {
   Class.forName("com.mysql.jdbc.Driver");
   String url="jdbc:MySQL://127.0.0.1:3306/test";
   String sql="insert into student1 values(?,?,?)";
   Connection con=DriverManager.getConnection(url, "root", "root");
   PreparedStatement smt=con.prepareStatement(sql);
   smt.setString(1, "S01");
   smt.setString(2, "ADMIN");
   File file=new File("d://a.jpg");
   fis=new FileInputStream(file);
   smt.setBinaryStream(3, fis, file.length());
   int i=smt.executeUpdate();
   System.out.println(i);
   smt.close();
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   if(fis!=null){
   try {
    fis.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   }
  }
  
}
}

但是我运行出错了,错误如下:
java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

TOP_D54PGN8O@98JT}JHW$3.jpg (171.45 KB, 下载次数: 83)

把BLOB类型存数据的代码

把BLOB类型存数据的代码

A@CJ((@X[XPQH4(}BQLWBTG.jpg (96.04 KB, 下载次数: 70)

数据库信息

数据库信息

1 个回复

倒序浏览

回帖奖励 +1

我还在学习中看不懂,真羡慕你
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马