100分求文件存储并读出到ORACEL的例子!
File file = new File("e:\\ejb.txt");
Reader fileReader = new FileReader(file);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:scott/127.0.0.1:1243:myInstance","user","pass");
String sql = "insert into table1(obj_id,content) VALUES(?,?)";
PreparedStatement ps=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE );
ps.setInt(1,2) ;
ps.setCharacterStream(2 ,fileReader,file.length()) ;//ntext max 450 !
ps.executeUpdate() ;
sql = "select * from table1 where obj_id= 2";
ResultSet rs=ps.executeQuery(sql);
rs.next() ;
Clob clob= rs.getClob(2) ;
String read = clob.getSubString( 1,(int)clob.length());
System.out.println(read) ;
具体的把读出的内容保存到文件很简单,自己写...
这是对于clob,对于blob也一样
<%@ page import="com.jspsmart.upload.*"%>
String fileName = "";
SmartUpload upload = new SmartUpload();
upload.initialize( this.getServletConfig(), request, response );
upload.upload();
Files files = upload.getFiles();
//here can get all files that have been selected.
if(files != null && files.getCount() != 0) {
com.jspsmart.upload.File file = files.getFile(0);
String name = file.getFileName();
fileName = name;
file.saveAs( fileName, com.jspsmart.upload.File.SAVEAS_PHYSICAL);
}
这是取得上传的文件并保存..
然后你在按上面那样保存到数据库...
也可以不保存直接传到数据库...
太贪心了吧?
上面的代码还不够吗 ?
干脆让别人给你做完得了...
String sql = "insert into table1(obj_id,content) VALUES(?,?)";
PreparedStatement ps=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE );
ps.setInt(1,2) ;
ps.setCharacterStream(2 ,fileReader,file.length()) ;//这一句就是把文件存入数据库拉 !
ps.executeUpdate() ;
这不是吗????
当然表的名字换成你自己的,字段换成你自己的...