[pgsql-jp: 26447] VisualBasicでラージオブジェクトの登録/検索

Hiroyuki Yamada hiroyuki @ rh.is.hitachizosen.co.jp
2002年 6月 19日 (水) 10:28:17 JST


山田@京都です。
 下記のようなPostgreSQLでラージオブジェクトを扱うプログラムは、Java言語で書
かれていますが
Visual Basic(ODBCドライバ経由)でもつくれるのでしょうか?ご教授の程、よろしく
おねがいします。

(例)
create table aaa_table(
  fff oid
);
---------------------
import java.sql.*;
import java.io.*;

public class Image_DB {
    public static void main(String[] args) {
        try {
            Class.forName("org.postgresql.Driver.");

            String url = "jdbc:postgresql://??????/?????";
            String user = "suzuki";
            String password = "abcdefg";
            Connection conn = DriverManager.getConnection(url, user,
password);

            File file = new File("C:\\aaaa\\big.txt");
            int fileLength = (int)file.length();
            FileInputStream fis = new FileInputStream(file);

            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO
aaa_table VALUES (?)");
            pstmt.clearParameters();
            pstmt.setAsciiStream(1, fis, fileLength);
            pstmt.executeUpdate();
            fis.close();

            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT fff FROM aaa_table");
            int count = 0;
            while (rs.next()) {
                count++;
                File outFile = new File("C:\\aaaa\\ccc" + count + ".txt");
                FileOutputStream fos = new FileOutputStream(outFile);
                BufferedInputStream bis = new
BufferedInputStream(rs.getAsciiStream(1));
                byte[] buff = new byte[4 * 1024];
                while (true) {
                    int size = bis.read(buff, 0, buff.length);
                    if (size == -1) break;
                    fos.write(buff, 0, size);
                }
                bis.close();
                fos.close();
            }
            conn.commit();

            rs.close();
            stmt.close();
           pstmt.close();
           conn.close();
        } catch(SQLException e) {
             e.printStackTrace();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}









pgsql-jp メーリングリストの案内