This is uploading
Import java.sql. *; import java.io. *; import java.util. *; import javax.servlet. *; import javax.servlet.http. *; import com.jspsmart.upload. *;
Public class upload extends httpservlet {
Private servletconfig config; / ** * init the servlet * / final public void init (servletconfig config) throws servletexception {this.config = Config;
Final Public ServletConfig GetServletconfig () {Return Config;
Public void doget (httpservletRequest request, httpservletResponse response) throws servletexception, oException {dopost (request, response);}
Public void dopost (httpservletRequest request, httpservletResponse response) throws servletexception, ioException {system.out.println ("============================== "); String id = null; SmartUpload mySmartUpload = new SmartUpload (); PrintWriter out = response.getWriter (); java.io.File file = null; try {Class.forName (" oracle.jdbc.driver.OracleDriver ") ;} Catch (java.lang.classnotfoundexception e) {system.err.print ("ClassNotFoundException:" E.getMessage ());}
Try {//class.forname ("Oracle.jdbc.driver.OracleDriver"); Connection Conn = DriverManager.getConnection ("JDBC: Oracle: Thin: @ 10.216.0.2: 1521: Orcl", "Test", "Test" );
Conn.setAutoCommit (False); // Sets manual commit to improve performance. StMT = conn.createstatement (); // initization mysmartupload.initialize (config, request, response);
MySmartupload.setmaxFileSize (500 * 1024); // upload mysmartupload.upload ();
// Take the data ID in the Text box = mysmartupload.getRequest (). GetParameter ("ID");
// Get files and file name com.jspsmart.upload.file myfile = mysmartupload.getfiles (); getfile (0); string filename = myfile.getFileName ();
if (! myfile.isming ()) {// save data myfile.saveas (filename, mysmartupload.save_physical; system.out.println ("============ FileName =" FileName "===="); file = new java.io.file (filename);
Java.io.inputStream Instream = New java.io.fileInputStream (file);
INT filesize = myfile.getsize (); byte [] bytes = new byte [filesis]; system.out.println ("============================================ ");
// Insert the data into the table string strsql = "INSERT INTO TEST (ID, Name, Content) VALUES ('" ID ",'" filename ", EMPTY_BLOB ())"; stmt.execute strsql);
ResultSet RS = Stmt.executeQuery ("SELECT Content from Zyw_test WHERE ID = '" "' for Update"); if (rs.next ()) {Oracle.Sql.Blob Blob = ((Oracle.jdbc.OracleResultset) ) rs) .getBLOB ( "content"); OutputStream outStream = blob.getBinaryOutputStream (); inStream.read (bytes); outStream.write (bytes); outStream.flush (); stmt.execute ( "commit"); outStream . close ();} instream.close (); stmt.close (); if (file! = null) // Delete file file.delete ();
Out.println ("UPLOAD Sucess");} else {outputln ("no file");}}}} catch (exception ex) {if (file! = null) file.delete (); out.println ("UPLOAD Fail "); ex.printstacktrace ();
System.out.println ("============================");}}
This is a download, showing pictures
Import java.sql. *; import java.io. *; import java.util. *; import javax.servlet. *; import javax.servlet.http. *;