Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #public class Pojo {
- String fnm;
- String lnm;
- InputStream b;
- public String getFnm() {
- return fnm;
- }
- public void setFnm(String fnm) {
- this.fnm = fnm;
- }
- public String getLnm() {
- return lnm;
- }
- public void setLnm(String lnm) {
- this.lnm = lnm;
- }
- public InputStream getB() {
- return b;
- }
- public void setB(InputStream b) {
- this.b = b;
- }
- }
- public class BusinessLogic {
- public boolean insert(Pojo bean)
- {
- boolean check_connection=false;
- try
- {
- System.out.println("inside Registration");
- Connection conn= (Connection) DBConnection.connect();
- String sql = "INSERT INTO image1 (first_name, last_name, photo) values (?, ?, ?)";
- PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
- ps.setString(1,bean.getFnm());
- ps.setString(2,bean.getLnm());
- ps.setBlob(3, bean.getB());
- ps.executeUpdate();
- check_connection =true;
- conn.close();
- }
- catch(Exception e)
- {
- System.out.println(""+e);
- }
- return check_connection;
- }
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String firstName = request.getParameter("firstName");
- String lastName = request.getParameter("lastName");
- InputStream inputStream = null; // input stream of the upload file
- Part filePart = request.getPart("photo");
- if (filePart != null) {
- // prints out some information for debugging
- System.out.println(filePart.getName());
- System.out.println(filePart.getSize());
- System.out.println(filePart.getContentType());
- // obtains input stream of the upload file
- inputStream = filePart.getInputStream();
- }
- Pojo p=new Pojo();
- p.setFnm(firstName);
- p.setLnm(lastName);
- if (inputStream != null) {
- // fetches input stream of the upload file for the blob column
- p.setB(inputStream);
- // statement.setBlob(3, inputStream);
- }
- BusinessLogic bl=new BusinessLogic();
- boolean b=bl.insert(p);
- if(b)
- {
- System.out.println("success");
- }
- else {
- System.out.println("success");
- }
- }
- public class DBConnection {
- public static Connection con;
- public static Connection connect()
- {
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- con=DriverManager.getConnection("jdbc:mysql://localhost:3306/img","root","");
- System.out.println("connected!!");
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- return con;
- }
- public static void close() throws SQLException
- {
- if(con!=null)
- {
- con.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement