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

解决方案 »

  1.   

    ResultSet rs;
    String s=new String(rs.getBinaryStream(int i).getBytes("ISO8859_1"), "GBK"); 
    i为select结果的第i列
      

  2.   

    使用java中的byte[]类型,get方法是byte[] getBytes[]
      

  3.   

    ResultSet rs=pstmt.executeQuery();
    rs.next();
    String s=new String(rs.getBytes("字段名"));
      

  4.   

    InputStream in = rs.getBinaryStream("字段名");
    String strFile = "c:\\1.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();
      

  5.   

    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;
    }