JDBC 从数据库中读取一张图片,怎么读出来的大小不一样
publicclassReadbigpic{publicstaticvoidmain(String[]args)throwsException,SQLException,...
public class Readbigpic {
public static void main(String[] args) throws Exception, SQLException, IOException {
test();
}
public static void test() throws ClassNotFoundException, SQLException, IOException{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc","root","1234");
String sql="select bigpic from big_pic";
PreparedStatement ps=conn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next()){
//以blob对象获取数据集中指定列的值
Blob b=rs.getBlob(1);
InputStream is=b.getBinaryStream();
File file=new File("20141314.jpg");
BufferedReader bfr=new BufferedReader(new InputStreamReader(is));
BufferedWriter bfw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
String line=null;
while((line=bfr.readLine())!=null){
bfw.write(line);
}
bfw.close();
bfr.close();
}
rs.close();
ps.close();
conn.close();
}
} 展开
public static void main(String[] args) throws Exception, SQLException, IOException {
test();
}
public static void test() throws ClassNotFoundException, SQLException, IOException{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc","root","1234");
String sql="select bigpic from big_pic";
PreparedStatement ps=conn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next()){
//以blob对象获取数据集中指定列的值
Blob b=rs.getBlob(1);
InputStream is=b.getBinaryStream();
File file=new File("20141314.jpg");
BufferedReader bfr=new BufferedReader(new InputStreamReader(is));
BufferedWriter bfw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
String line=null;
while((line=bfr.readLine())!=null){
bfw.write(line);
}
bfw.close();
bfr.close();
}
rs.close();
ps.close();
conn.close();
}
} 展开
1个回答
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询