用java 写入BLOB

发布时间:2020-08-10 14:18:10 作者:paodekuai
来源:ITPUB博客 阅读:133

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@]
推荐阅读:
  1. 用mysql存圖片
  2. 怎么用JavaScript读取和保存文件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

blob java 写入

上一篇:python2和3同时用pip的方法

下一篇:什么是软件设计中模块划分应遵循的准则

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》