bytes插入ORACLE的BLOB中的问题

xiaofenguser 2002-12-25 05:38:53
我为什么一直都无法正确的取出呢,每次都是下面的相同的一句(我转成字符串后的)
2.I!05:@sB??\G?.?$?2..!05:@LB3D-??
插入语句
String sql_insert="insert into test(id,content) values(?,?)";
byte bs[]=new xiao().encrypt(content);
PreparedStatement pstm=con.prepareStatement(sql_insert);
pstm.setString(1,id);
pstm.setBytes(2,bs);
i=pstm.executeUpdate();
String str=new xiao().uncrypt(bl);//这里得到的是正确的
查出语句:
String sql_query="select * from test";
PreparedStatement pstm=con.prepareStatement(sql_query);
ResultSet rs=pstm.executeQuery();
while(rs.next())
{
byte bl[]=rs.getBytes("content");
id=rs.getString("id");
String str=new xiao().uncrypt(bl);//这里得到的就是错误的
KeyModel km=new KeyModel(id,str);
kv.add(km);//kv是Vector型的
}
请帮忙啊!
...全文
142 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaofenguser 2002-12-26
  • 打赏
  • 举报
回复
谢谢,继续UP
dou1204 2002-12-26
  • 打赏
  • 举报
回复
thanks!
xiaofenguser 2002-12-26
  • 打赏
  • 举报
回复
图片的数据库存储
---摘自互联网

import java.io.*;
import java.sql.*;
public class InsertBlob {
public static void main(String args[]) {

String username;
String password;
String url;
String dropString;
String createString;

username = "system";

password = "manager";

// The URL that will connect to TECFA's MySQL server
// Syntax: jdbc:TYPEachineort/DB_NAME
url = "jdbcracle:thin:@cs05:1521s05";
// ---- configure END

// INSTALL/load the Driver (Vendor specific Code)
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try {
Connection con;
Statement stmt;

// Establish Connection to the database at URL with usename and password
con = DriverManager.getConnection(url, username, password);
System.out.println ("Ok, connection to the DB worked. Let's see if we can insert something:");

// con.setAutoCommit(false);

FileInputStream fis=null;
File file = new File("z.jpg");
try{
fis = new FileInputStream(file);
} catch(FileNotFoundException e) {}
PreparedStatement ps = con.prepareStatement("insert into binary_data values (?,?,?,?,?,?)");
ps.setInt(1,1);
ps.setString(2,"樱花");
ps.setBinaryStream(3,fis,3098);
ps.setString(4,"z.jpg");
ps.setString(5,"3098");
ps.setString(6,"jpg");
ps.executeUpdate();
ps.close();
try{
fis.close();
} catch(IOException e) {}

System.out.println ("Image Items have been inserted, you can now run the QueryCoffees program");
// Close resources
// stmt.close();
con.close();
}
// print out decent erreur messages
catch(SQLException ex) {
System.err.println("==> SQLException: ");
while (ex != null) {
System.out.println("Message: " + ex.getMessage ());
System.out.println("SQLState: " + ex.getSQLState ());
System.out.println("ErrorCode: " + ex.getErrorCode ());
ex = ex.getNextException();
System.out.println("");
}
}

}
}
dou1204 2002-12-26
  • 打赏
  • 举报
回复
抱歉,问个问题,你的BLOB在JSP中怎么提交的?能给个例子看看吗?
我是想把客户端的FILE存到数据库中,谢谢!
tomatowitch 2002-12-26
  • 打赏
  • 举报
回复
up
dou1204 2002-12-25
  • 打赏
  • 举报
回复
上次帮我解决了问题,谢谢.关注! :)

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧