哪里错了
package com.itbaizhan;
import java.io.*;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* Blob类型操作测试类
*/
public class BlobTest {
/**
*向movie表中插入数据
*/
public void insertMoive(String moviename, InputStream is){
Connection connection = null;
PreparedStatement ps = null;
try{
//获取链接
connection = JdbcUtils.getConnection();
//获取PrepareStatement对象
ps = connection.prepareStatement("insert into movie values(default,?,?)");
//绑定参数
ps.setString(1,moviename);
ps.setBlob(2,is);
ps.executeUpdate();
}catch (Exception e){
e.printStackTrace();
}finally {
JdbcUtils.closeResource(ps,connection);
}
}
/**
* 根据影片ID查询影片信息
* @param movieid
*/
public void selectMovieBlob(int movieid){
Connection conn =null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
//获取连接
conn =JdbcUtils.getConnection();
//创建PreparedStatement对象
ps = conn.prepareStatement("select * from movie where movieid = ?");
//绑定参数
ps.setInt(1,movieid);
//执行sql
rs = ps.executeQuery();
while(rs.next()){
int id = rs.getInt("movieid");
String name = rs.getString("moviename");
System.out.println(id+" "+name);
//获取blob类型的数据
Blob blob = rs.getBlob("poster");
//获取能够从Blob类型的列中读取数据的IO流
InputStream is = blob.getBinaryStream();
//创建文件输出字节流对象
OutputStream os = new FileOutputStream(id+"_"+name+".jpg");
//操作流完成文件的输出处理
byte[] buff = new byte[1024];
int len;
while((len = is.read(buff)) != -1){
os.write(buff,0,len);
}
os.flush();
is.close();
os.close();
}
}catch(Exception e){
e.printStackTrace();
}finally{
JdbcUtils.closeResource(rs,ps,conn);
}
}
public static void main(String[] args) throws FileNotFoundException {
BlobTest b = new BlobTest();
// InputStream is = new FileInputStream(new File("D:/截图/数据库/MySQL中DML操作/MySql Blob类型.jpg"));
// b.insertMoive("Blob类型",is);
b.selectMovieBlob(1);
}
}
java.io.FileNotFoundException: 1Blob??.jpg (文件名、目录名或卷标语法不正确。)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:126)
at com.itbaizhan.BlobTest.selectMovieBlob(BlobTest.java:60)
at com.itbaizhan.BlobTest.main(BlobTest.java:83)
Process finished with exit code 0