sql server的表中有一个字段是binary类型的,在java程序中如何将其读出来并转换成中文字符串,并且能正常显示出来??

解决方案 »

  1.   

    String s=rs.getBinaryStream().toString();
      

  2.   

    错了,上面改成getBinaryStream(int columncount)
      

  3.   

    InputStream in = rs.getBinaryStream("字段名");
    String strFile = "c:\\1.jpg";//假设是一个jpg,读出之后写到这个文件
    OutputStream out = new FileOutputStream(strFile);
    byte[] bytes = new byte[1024];
    while(in.read(bytes,0,1024) != -1){
      out.write(bytes);
    }
    out.close();
    in.close();
      

  4.   

    ft,看错题目了.InputStream in = rs.getBinaryStream("字段名");
    BufferedReader in = new BufferedReader(new InputStreamReader(in));
    String s="";
    int nLine =0;
    String strResult = "";
    while((s=in.readLine())!=null){
      strResult  = strResult +s;
    }