mysqlblobjava
⑴ jsp/java读取mysql的blob类型字段中文乱码问题 代码如下,但是出来的是乱码
知道了.
(2):手动插入中文数据,insert.....然后在mysql的窗口中查看是否正常显示.
(3):根据测试结果确定是页面问题还是数据库设置问题
  1:如果是页面问题,相信你知道,怎么解决.
  2:如果是数据插入以后就变成了乱码,那就是你的数据库字符集有问题,找到my.ini
[client]
port=3306
[mysql]
加上:default-character-set=gbk
也可以通过数据库设置向导来设置(windows下才有)
 3:如果还是乱码的话那就把页面和数据库的字符设置成一样的就好了
希望对你有帮助
一般还是建议使用jbk
另外,虚机团上产品团购,超级便宜
⑵ mysql blob在java中转化成string类型,打印出来[B@a99013是什么类型的数据,怎样在页面显示
从mysql中去取出的是Blob类型,要转String通过new String(blob.getBytes((long)1, (int)blob.length()));来转,就是想要的数据
⑶ 使用java语言操作,如何来实现MySQL中Blob字段的存取
/** 
* Title: BlobPros.java 
* Project: test 
* Description: 把图片存入mysql中的blob字段,并取出 
* Call Mole: mtools数据库中的tmp表 
* File: C:downloadsluozsh.jpg 
* Copyright: Copyright (c) 2003-2003 
* Company: uniware 
* Create Date: 2002.12.5 
* @Author: ChenQH 
* @version 1.0 版本* 
* 
* Revision history 
* Name Date Description 
* ---- ---- ----------- 
* Chenqh 2003.12.5 对图片进行存取 
* 
* note: 要把数据库中的Blob字段设为longblob 
* 
*/ 
//package com.uniware; 
import java.io.*; 
import java.util.*; 
import java.sql.*; 
public class BlobPros 
{ 
private static final String URL = "jdbc:mysql://10.144.123.63:3306/mtools?user=wind&password=123&useUnicode=true"; 
private Connection conn = null; 
private PreparedStatement pstmt = null; 
private ResultSet rs = null; 
private File file = null; 
public BlobPros() 
{ 
} 
/** 
* 向数据库中插入一个新的BLOB对象(图片) 
* @param infile 要输入的数据文件 
* @throws java.lang.Exception 
*/ 
public void blobInsert(String infile) throws Exception 
{ 
FileInputStream fis = null; 
try 
{ 
Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
conn = DriverManager.getConnection(URL); 
file = new File(infile); 
fis = new FileInputStream(file); 
//InputStream fis = new FileInputStream(infile); 
pstmt = conn.prepareStatement("insert into tmp(descs,pic) values(?,?)"); 
pstmt.setString(1,file.getName()); //把传过来的第一个参数设为文件名 
//pstmt.setBinaryStream(2,fis,(int)file.length()); //这种方法原理上会丢数据,因为file.length()返回的是long型 
pstmt.setBinaryStream(2,fis,fis.available()); //第二个参数为文件的内容 
pstmt.executeUpdate(); 
} 
catch(Exception ex) 
{ 
System.out.println("[blobInsert error : ]" + ex.toString()); 
} 
finally 
{ 
//关闭所打开的对像// 
pstmt.close(); 
fis.close(); 
conn.close(); 
} 
} 
/** 
* 从数据库中读出BLOB对象 
* @param outfile 输出的数据文件 
* @param picID 要取的图片在数据库中的ID 
* @throws java.lang.Exception 
*/ 
public void blobRead(String outfile,int picID) throws Exception 
{ 
FileOutputStream fos = null; 
InputStream is = null; 
byte[] Buffer = new byte[4096]; 
try 
{ 
Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
conn = DriverManager.getConnection(URL); 
pstmt = conn.prepareStatement("select pic from tmp where id=?"); 
pstmt.setInt(1,picID); //传入要取的图片的ID 
rs = pstmt.executeQuery(); 
rs.next(); 
file = new File(outfile); 
if(!file.exists()) 
{ 
file.createNewFile(); //如果文件不存在,则创建 
} 
fos = new FileOutputStream(file); 
is = rs.getBinaryStream("pic"); 
int size = 0; 
/* while(size != -1) 
{ 
size = is.read(Buffer); //从数据库中一段一段的读出数据 
//System.out.println(size); 
if(size != -1) //-1表示读到了文件末 
fos.write(Buffer,0,size); 
} */ 
while((size = is.read(Buffer)) != -1) 
{ 
//System.out.println(size); 
fos.write(Buffer,0,size); 
} 
} 
catch(Exception e) 
{ 
System.out.println("[OutPutFile error : ]" + e.getMessage()); 
} 
finally 
{ 
//关闭用到的资源 
fos.close(); 
rs.close(); 
pstmt.close(); 
conn.close(); 
} 
} 
public static void main(String[] args) 
{ 
try 
{ 
BlobPros blob = new BlobPros(); 
//blob.blobInsert("C:Downloadsluozsh1.jpg"); 
blob.blobRead("c:/downloads/1.jpg",47); 
} 
catch(Exception e) 
{ 
System.out.println("[Main func error: ]" + e.getMessage()); 
} 
} 
}
⑷ java mysql数据库 Blob乱码 求救。
应该是
字符集
的问题。
最好都设成utf-8
包括数据库,后台,还有前台页面的编码
⑸ java 以二进制流的方式读取mysql 中的blob文件,并写入本地文件夹下
//配置数据库连接驱动    
            String sql = xxxxxxxx;//要查询的sql
            PreparedStatement ps = conn.prepareStatement(sql); 
            String path = xxxxxxx;
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                InputStream is = rs.getBlob(x).getBinaryStream();//x为要取的BLOB位置
                FileOutputStream os = new FileOutputStream(path + "//"
                        + "存放的文件名"+“.zip”);
                byte[] buff = new byte[1024];
                while ((is.read(buff)) != -1) {
                    os.write(buff);
                }
                os.close();
                is.close();
            }
            ps.close();
            conn.close();
