Criei um método de insert e gostaria se a forma como foi colocada segue a melhor prática.
Gostaria de deixar o mais generico possível, pois nessa classe ainda deve ter delete e select
public static void insert(File f, String tipoCont, String tipoDoc) throws SQLException {
try {
FileInputStream fis = new FileInputStream(f);
int len = (int)f.length();
String insert = (“insert into dbo.files_store (file_name, content, update_date, content_type, myme, deleted) values (?, ?, getdate(), ?, ?, ?)”);
String select = (“select file_name from dbo.files_store where file_name = ?”);
String update = (“update dbo.files_store set file_name = ?, content = ?, update_date = getdate(), content_type = ?, myme = ?, deleted = ?”);
stmt = getConnection().prepareStatement(select);
if (stmt == null){
stmt = getConnection().prepareStatement(insert);
stmt.setString(1,f.getName());
stmt.setBinaryStream(2, fis, len);
stmt.setString(3, tipoDoc);
stmt.setString(4, tipoCont);
stmt.setString(5, “N”);
}
else{
stmt = getConnection().prepareStatement(update);
stmt.setString(1,f.getName());
stmt.setBinaryStream(2, fis, len);
stmt.setString(3, tipoDoc);
stmt.setString(4, tipoCont);
stmt.setString(5, “N”);
}
stmt.executeUpdate();
stmt.close();
con.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}