当前位置: 技术问答>java相关
高分求救:谁用过JSP处理ORACLE数据库中的LONG RAW类型字段
来源: 互联网 发布时间:2015-04-11
本文导语: 各位,帮帮我好吗? | String sSql=""update test set content = ? where id = 1"; String=content"my god";//你的内容 PreparedStatement stmt = conn.prepareStatement(sSql); byte[] pic = content.getBytes(); InputStreamReader bais...
各位,帮帮我好吗?
|
String sSql=""update test set content = ? where id = 1";
String=content"my god";//你的内容
PreparedStatement stmt = conn.prepareStatement(sSql);
byte[] pic = content.getBytes();
InputStreamReader bais = new InputStreamReader(new ByteArrayInputStream(pic));
stmt.setCharacterStream(1, bais, pic.length);
stmt.execute();
写2k以上文本不用LONG RAW
用long就可以了
以上程序是针对LONG的
写long raw大概应该用setBinaryStream
试一试...
String=content"my god";//你的内容
PreparedStatement stmt = conn.prepareStatement(sSql);
byte[] pic = content.getBytes();
InputStreamReader bais = new InputStreamReader(new ByteArrayInputStream(pic));
stmt.setCharacterStream(1, bais, pic.length);
stmt.execute();
写2k以上文本不用LONG RAW
用long就可以了
以上程序是针对LONG的
写long raw大概应该用setBinaryStream
试一试...
|
写入:
out = response.getWriter();
Connection conn = DriverManager.getConnection("", "", "");
//INSERT A FILE INTO THE DATABASE!
File file = new File("D:\d.bmp");
FileInputStream fis = new FileInputStream(file);
String strsql ="INSERT INTO tp(tp,dm) VALUES (?,'01')";
PreparedStatement ps = conn.prepareStatement(strsql);
ps.setBinaryStream(1, fis, (int)(file.length()));
ps.executeUpdate();
out.println("INSERT FILE OK:::::");
ps.close();
fis.close();
读出:
PreparedStatement pres = conn.prepareStatement("SELECT tp FROM tp WHERE dm='01'");
ResultSet res = pres.executeQuery();
if (res != null)
{
while(res.next())
{
InputStream is = res.getBinaryStream(1);
// use the stream in some way here
OutputStream outstr = new BufferedOutputStream( new FileOutputStream("d:\new.bmp"));
// Read the URL and write it to a file
byte bufferb[] = new byte[64];
// Buffer to store lines
int nread;
while(0
out = response.getWriter();
Connection conn = DriverManager.getConnection("", "", "");
//INSERT A FILE INTO THE DATABASE!
File file = new File("D:\d.bmp");
FileInputStream fis = new FileInputStream(file);
String strsql ="INSERT INTO tp(tp,dm) VALUES (?,'01')";
PreparedStatement ps = conn.prepareStatement(strsql);
ps.setBinaryStream(1, fis, (int)(file.length()));
ps.executeUpdate();
out.println("INSERT FILE OK:::::");
ps.close();
fis.close();
读出:
PreparedStatement pres = conn.prepareStatement("SELECT tp FROM tp WHERE dm='01'");
ResultSet res = pres.executeQuery();
if (res != null)
{
while(res.next())
{
InputStream is = res.getBinaryStream(1);
// use the stream in some way here
OutputStream outstr = new BufferedOutputStream( new FileOutputStream("d:\new.bmp"));
// Read the URL and write it to a file
byte bufferb[] = new byte[64];
// Buffer to store lines
int nread;
while(0