** PLSQLストアドを呼び出す(Oracle) [#s0d46313] #setlinebreak(on); package example; import java.io.*; import java.sql.*; import java.sql.*; import oracle.jdbc.driver.*; public class TestBlob { static final String dbuser = "user"; static final String dbpass = "pass"; static final String constring = "jdbc:oracle:thin:@localhost:1521:orcl"; // ファイルPATH static String insertFileName = "c:/tmp/test.csv"; public static void main(String[] args) { try { byte[] data = getByteArray(insertFileName); Connection con = null; Class.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection(constring,dbuser,dbpass); con.setAutoCommit(false); cstmt = con.prepareCall("{call testProc(?, ?)}"); cstmt.setInt(1, empno); cstmt.registerOutParameter(2, OracleTypes.BLOB); cstmt.executeQuery(); BLOB blob = (BLOB)cstmt.getObject(2); blob.putBytes(1, data); con.commit(); con.close(); } catch (Exception e){ e.printStackTrace(); } } /** * ファイル内容をbyte配列で取得する * @param filePath * @return byte[] * @throws Exception */ public static byte[] getByteArray(String filePath) throws Exception { StringBuffer sb = new StringBuffer(); BufferedReader reader = new BufferedReader(new FileReader(filePath)); String rec = null; while ((rec = reader.readLine()) != null) { sb.append(reader.readLine()); } return sb.toString().getBytes(); } }