shakti sharma: dear bro can u tell me exmaple saving file in db using servlet
Jalesingh yadav: Try this one it stores file in database in binary format.
File fBlob = new File ("<your_file_path>"); FileInputStream is = new FileInputStream(fBlob); // statement is PreparedStatement type, in the below line 1 //represents in your database first attribute is type of 'blob' like //CREATE TABLE picture ( //IMAGE BLOB, //ID INTEGER AUTO_INCREMENT, //PRIMARY KEY (ID) //) ; statement.setBinaryStream(1, is, (int) fBlob.length()); statement.execute();
if the above code is create any problem then replace last two lines by statement.setBlob(1, is); statement.executeUpdate();
i never tried this one, because this is not a good method it creates problem when we need to store thousand of files. it stores file in database in binary format.
Abhijeet kumar: and now after the jdbc4.0 you can play with the driver class both for oracle and mysql. now the "class.forname();" is optional the jdbc4.0 automatically loads and register the drive when u add tha jar file to the class path or the corresponding project.
Jalesingh yadav: ya bro we can set class path for database connector. For mysql download connector jar file from here : "http://dev.mysql.com/downloads/connector/j/" and set path of this file in class path of my computer environment variables.