Java高级数据类型

来源:互联网 发布:巨人网络 股票分析 编辑:程序博客网 时间:2024/06/11 20:44
Blob:
        写入:
                FileInputStream fis = new FileInputStream(file);
                pstmt.setBinaryStream(1, fis, (int) file.length());
                ... pstmt.close(); 
                fis.close(); 
        
        读取:
                Blob blob = rs.getBlob("photo");
                ImageIcon icon = new ImageIcon(blob.getBytes(1, (int)blob.length()));
                JLabel lPhoto = new JLabel(icon);
                setLayout(new GridLayout(1, 1));
                add(lPhoto); 

Clob:
        写入:
                FileInputStream fis = new FileInputStream(file);
                pstmt.setAsciiStream(1, fis, (int)file.length()); 

        读取:
                Clob clob = rs.getClob("memo");
                InputStreamReader in = new InputStreamReader(clob.getAsciiStream());
                JTextArea text = new JTextArea(readString(in));
                setLayout(new GridLayout(1, 1));
                add(text);

                public static String readString(InputStreamReader in) throws IOException {
                    StringBuffer buf = new StringBuffer();
                    int n;
                    char[] b = new char[1024];
                    while((n = in.read(b)) > 0)
                        buf.append(b, 0, n);
                    return buf.toString();
                }