Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package onlinecontactbackup;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class EnrollmentServlet extends HttpServlet {
- static final String DataBaseURL = "jdbc:mysql://localhost:3306/phonebookbackup?"
- + "user=root&password=null";
- public void doSend(HttpServletRequest request,HttpServletResponse response)
- throws IOException,ServletException{
- Connection conn = null;
- response.setContentType("text/plain");
- PrintWriter outResponse = response.getWriter();
- try{
- Class.forName("com.mysql.jdbc.Driver");
- } catch(ClassNotFoundException e){
- throw new ServletException("Unable to load JDBC Driver");
- }
- try{
- String userInputName =
- request.getParameter("FullNames");
- String userInputUserName =
- request.getParameter("UserName");
- String userInputEmail =
- request.getParameter("Email");
- String userInputPassword =
- request.getParameter("Password");
- String userInputVerifyPassword =
- request.getParameter("VerifyPassword");
- conn = DriverManager.getConnection(DataBaseURL);
- PreparedStatement psmt =
- conn.prepareStatement("INSERT INTO RegistrationT VALUES(?,?,?,?,?)");
- psmt.setString(2, userInputName);
- psmt.setString(3, userInputUserName);
- psmt.setString(4, userInputEmail);
- psmt.setString(5, userInputEmail);
- psmt.setString(6, userInputPassword);
- psmt.setString(7, userInputVerifyPassword);
- psmt.execute();
- conn.close();
- } catch(SQLException sqe){
- throw new ServletException("SQL call failed");
- } catch(Exception e){
- throw new ServletException(e.getMessage());
- } finally{
- if(conn!=null){
- try{
- conn.close();
- } catch(SQLException e){
- throw new ServletException("Connection close failed");
- }
- }
- }
- }
- public void doGet(HttpServletRequest request,HttpServletResponse response)
- throws IOException,ServletException{
- Connection conn = null;
- response.setContentType("text/plain");
- PrintWriter outResponse = response.getWriter();
- try{
- Class.forName("com.mysql.jdbc.Driver");
- } catch(ClassNotFoundException e){
- throw new ServletException("Unable to load JDBC driver");
- }
- try{
- String UserName = request.getParameter("UserName");
- System.out.print("UserName=" +UserName);
- conn = DriverManager.getConnection(DataBaseURL);
- Statement stmt = conn.createStatement();
- String SQlQuery = "SELECT* "
- + "FROM LoginT" + "WHERE UserName='"
- + UserName + "'";
- ResultSet rs = stmt.executeQuery(SQlQuery);
- if(rs.next()){
- outResponse.println(rs.getString(2));
- outResponse.println(rs.getString(3));
- } else {
- outResponse.println("Record Not Found!");
- }
- conn.close();
- } catch(SQLException e){
- throw new ServletException("SQL call failed!");
- } catch(Exception e){
- throw new ServletException(e.getMessage());
- } finally{
- if(conn!=null){
- try{
- conn.close();
- } catch(SQLException e){
- throw new ServletException("Connection close failed!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment