I want to insert & retrive image & textfile into Mysql Database.
How to do it?
I want to insert & retrive image & textfile into Mysql Database.
How to do it?
public boolean storeImg()
throws Exception
{
boolean written = false;
//opening db
Class.forName(dbDriver);
ConrsIn = DriverManager.getConnection(dburl,dbUser,dbPasswor t);
if (ConrsIn == null)
written = false;
else
{
try
{
Stmtrsext = ConrsIn.createStatement();
//int intID = rsext.getInt("id");
// ******* <BLOB> **********
file = new File(PICTURE);
fis = new FileInputStream(file);
ps = ConrsIn.prepareStatement("insert into PICTURE values (?,?)");
// ***use as many ??? as you need to insert in the exact order!!!!*** ps.setString(1,file.getName());
ps.setBinaryStream(2,fis,(int)file.length());
ps.executeUpdate();
ps.close();
fis.close();
// ****** </BLOB> ******
written = true;
}
catch (SQLException E)
{
written = false;
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
}
//close db conn
//rsIn.close();
ConrsIn.close();
return written;
}
this should do! just need to insert your values (also don't know how you open your db con! important for the blob-img storage is the part in between ***BLOB****!!!
Bookmarks