import java.io.*;import java.sql.*;public class blvb{public static void main(String[] args){try {if(args.length != 2){Sy
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();
}
}
}
--结束END--
本文标题: 用java 写入BLOB
本文链接: https://lsjlt.com/news/233760.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0