大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

用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://dzwzjz.com/article/gcgspg.html
在线咨询
服务热线
服务热线:028-86922220
TOP