ITPub博客

首页 > 应用开发 > Java > 用java 写入BLOB

用java 写入BLOB

原创 Java 作者:paodekuai 时间:2006-05-05 11:03:02 0 删除 编辑

import java.io.*;
import java.sql.*;

public class blvb
{
public static void main(String[] args)
{
try {
if(args.length != 2)
{
System.out.println("Usage:");
System.out.println("java lvb ");
System.exit(0);
}

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@DataBaseName:1521:InstanceName", "test", "1234");
PreparedStatement pst = connection.prepareStatement("insert into BLOB_TEST values (" + args[0] + ", ?)");
InputStream in = null;
File f = null;
f = new File(args[1]);
System.out.println("File: " + f.getAbsolutePath());
in = new FileInputStream(f);
//If the column type is clob, you can call method pst.setAsciiStream(int parameterIndex,InputStream x,int length)
pst.setBinaryStream(1,in,(int)f.length());
try {
pst.executeUpdate();
} catch(Exception e){e.printStackTrace();}
in.close();
}
catch (SQLException ex) {
System.err.println("Cannot connect to this database.");
System.err.println(ex);
ex.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/98828/viewspace-832737/,如需转载,请注明出处,否则将追究法律责任。

下一篇: MySQL 中文手册
请登录后发表评论 登录
全部评论

注册时间:2011-05-23

  • 博文量
    74
  • 访问量
    2644223