public class PostAbstractDao { public static PostAbstract insert(PostAbstract bean) { try { PathReturn path = new PathReturn(); String realpath = path.getPath();// it will return the path of the myeclipse server(E:\MyeclipseApps\.metadata\.me_tcat\webapps\MedicalConference) System.out.println("path is" + realpath); int gid = bean.getGid(); String email = bean.getEmail(); FormFile file = bean.getFile(); // Get the servers upload directory real path name String filePath = realpath + "abstracts"; String dbpath = "D:\\abstracts\\" + file.getFileName(); // create the upload folder if not exists File folder = new File(filePath); if (!folder.exists()) { folder.mkdirs(); } String fileName = file.getFileName(); if (!("").equals(fileName)) { System.out.println("Server path:" + filePath); File newFile = new File(filePath, fileName); if (!newFile.exists()) { FileOutputStream fos = new FileOutputStream(newFile); fos.write(file.getFileData()); fos.flush(); fos.close(); } } Connection con = (Connection) new DB2Connection() .getDatabaseConnection(); String sql = "insert into user_posts(gid,posts,email) values(?,?,?) "; PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, gid); ps.setString(2, dbpath); ps.setString(3, email); int ok = ps.executeUpdate(); if (ok > 0) { bean.setValid(true); } } catch (SQLException e) { e.printStackTrace(); } catch (NullPointerException nl) { nl.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } return bean; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)