How to insert image into database in Java -


i want insert image database through "browse" button. problem in line, ps.setblob(l16, inputstream)? line shows error every time.

my code is:

class.forname("com.mysql.jdbc.driver");    connection con=drivermanager.getconnection(   "jdbc:mysql://localhost:3306/hostel_management","root","");    preparedstatement ps= con.preparestatement("insert student_info values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");    ps.setstring(1, tf1.gettext()); ps.setstring(2, tf2.gettext()); . . . ps.setstring(15, tf15.gettext());  inputstream inputstream = new fileinputstream(new file(tf16.gettext()));  ps.setblob(16, inputstream);  ps.execute();   joptionpane.showmessagedialog(null, "successfully inserted", "message", joptionpane.error_message);  con.close(); 

convert image base64, , save text database. when want back, , revert bitmap , use it.

use apache commons @ best way

base64.encode(fileutils.readfiletobytearray(file)); 

for decoding it,

inputstream stream = new bytearrayinputstream(base64.decode(image.getbytes(), base64.default)); 

where image string contains base64 text. let me know if want more help.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -