Advertisement
Guest User

jdbc_connection

a guest
Jun 23rd, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package com.shubh;
  2.  
  3. import java.io.IOException;
  4. import java.sql.*;
  5. import java.io.*;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. public class Download extends HttpServlet {
  13.     private static final long serialVersionUID = 1L;
  14.     public Download() {
  15.         super();
  16.         // TODO Auto-generated constructor stub
  17.     }
  18.  
  19.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  20.         // TODO Auto-generated method stub
  21.         Connection con;
  22.         Statement s;
  23.         ResultSet r;
  24.         try{
  25.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  26.             String url="jdbc:mysql://localhost:3306/";
  27.             String user="sky";
  28.             String pass="root123";
  29.             String dbname="student";
  30.            
  31.             con=DriverManager.getConnection(url+dbname, user, pass);
  32.            
  33.             String password=request.getParameter("password");
  34.             String loginid=request.getParameter("login");
  35.             String query="select * from login where password='"+password+"' and loginid='"+loginid+"'";
  36.  
  37.             s=con.createStatement();
  38.             r=s.executeQuery(query);
  39.             if(r.next())
  40.             {
  41.                 response.setContentType("text/html");
  42.                 PrintWriter out=response.getWriter();
  43.                 out.println("<html>");
  44.                 out.println("<body>");
  45.                 out.println(loginid+password);
  46.                 out.println("</html>");
  47.                 out.println("</body>");
  48.             }
  49.  
  50.         } catch (Exception e) {
  51.             // TODO Auto-generated catch block
  52.             e.printStackTrace();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement