-->

  • Ranchi University Java Mid Sem Exam Paper with solution


    Ranchi University Java Mid Sem Exam Paper with solution 
     
     
     

    Ranchi University Java Mid Sem Exam Paper with solution

     
     
    Ranchi University Java Mid Sem Exam Paper with solution


     

     
    1. Write using html and servlet to insert data in MySql database.


    A simple servlet code to accept values from a form and insert it into database using JDBC Code.

     

     

    <!DOCTYPE html>  
    <html>  
        <head>  
            <meta charset="ISO-8859-1">  
            <title>Insert title here</title>  
        </head>  
        <body>  
            <form method="Post" action="/Servlet">  
                <div>  
                    <label>Enter Movie Name: </label>  
                    <input type="text" name="name">  
                </div>  
                <div>  
                    <label>Enter Actor Name: </label>     
                    <input type="text" name="actor">  
                </div>  
                <div>  
                    <label>Enter Actress Name: </label>  
                    <input type="text" name="actress">    
                </div>  
                <div>  
                    <label>Enter Director Name: </label>      
                    <input type="text" name="director">  
                </div>  
                <div>  
                    <label>Enter Release Date: </label>   
                    <input type="text" name="rDate"blue>  
                </div>  
                <div>  
                    <label>Enter Rating Point: </label>  
                    <input type="text" name="rPoint">     
                </div>  
                <div>  
                    <input type="submit" value="Add movie">  
                </div>  
            </form>  
        </body>  
    </html> 
    
    
    
    

     

     

     

        import java.io.IOException;    
        import java.io.PrintWriter;    
        import java.sql.*;    
        import javax.servlet.ServletException;    
        import javax.servlet.annotation.WebServlet;    
        import javax.servlet.http.HttpServlet;    
        import javax.servlet.http.HttpServletRequest;    
        import javax.servlet.http.HttpServletResponse;    
            
           
        @WebServlet("/MovieServlet")    
        public class MovieServlet extends HttpServlet {    
            private static final long serialVersionUID = 1L;    
                   
               
            public MovieServlet() {    
                super();    
                // TODO Auto-generated constructor stub    
            }    
            
               
            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    
                // TODO Auto-generated method stub    
                response.getWriter().append("Served at: ").append(request.getContextPath());    
            }    
            
              
            protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    
                    
                PrintWriter pw;    
                response.setContentType("text/html");    
                pw=response.getWriter();    
                    
                    
                String name=request.getParameter("name");    
                String actor=request.getParameter("actor");    
                String actress=request.getParameter("actress");    
                String director=request.getParameter("director");    
                String rDate=request.getParameter("rDate");    
                String rPoint=request.getParameter("rPoint");    
                float rating=Float.parseFloat(rPoint);    
                    
                    
                try    
                {    
                    Class.forName("com.mysql.jdbc.Driver");    
                    String url="jdbc:mysql://localhost:3306/mcapracticals";    
                    String user="root";    
                    String password="admin";    
                        
                    Connection con=DriverManager.getConnection(url, user, password);    
                    String query="Insert into movie(name,actor,actress,director,releaseDate,ratingPoint) values (?,?,?,?,?,?);";    
                    PreparedStatement pstmt=con.prepareStatement(query);    
                    pstmt.setString(1, name);    
                    pstmt.setString(2, actor);    
                    pstmt.setString(3,actress);    
                    pstmt.setString(4, director);    
                    pstmt.setString(5, rDate);    
                    pstmt.setFloat(6,rating);    
                        
                    int x=pstmt.executeUpdate();    
                        
                    if(x==1)    
                    {    
                    pw.println("Values Inserted Successfully");    
                    }    
                        
                }    
                catch(Exception e)    
                {    
                        e.printStackTrace();    
                }    
                    
                    
                pw.close();    
            }    
            
        }   
    

     

     

     

    Uploading.....

     


    Disclaimer

     

    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

     

  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.