RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
用java写入BLOB

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

成都创新互联公司成立与2013年,是专业互联网技术服务公司,拥有项目成都网站制作、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元赤城做网站,已为上家服务,为赤城各地企业和个人服务,联系电话:13518219792

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@]
文章名称:用java写入BLOB
文章来源:http://sczitong.cn/article/gcgspg.html