Guest User

Untitled

a guest
Oct 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. public Conexion(){
  2. }
  3.  
  4. public Connection getConecction(){
  5. try{
  6. DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  7. System.out.println("Conectando base de datos");
  8. Connection connection = DriverManager.getConnection(
  9. "jdbc:oracle:thin:@//localhost:1521/oracledtb", "misofertasdb", "123");
  10. return connection;
  11. }catch (Exception e){
  12. System.out.println("La excepcion es: "+e);
  13. return null;
  14. }
  15. }
  16. public CallableStatement conn(String procedure){
  17. try{
  18. DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  19. System.out.println("Conectando base de datos");
  20. Connection connection = DriverManager.getConnection(
  21. "jdbc:oracle:thin:@//localhost:1521/oracledtb", "misofertasdb", "123");
  22. CallableStatement stm = connection.prepareCall(procedure);
  23. return stm;
  24. }catch (Exception e){
  25. System.out.println("La excepcion es: "+e);
  26. return null;
  27. }
  28. }
  29. }
  30.  
  31. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  32. throws ServletException, IOException {
  33. /*Datos*/
  34. String username = request.getParameter("username");
  35. String password = request.getParameter("password");
  36. String nombre = "";
  37. String apellido = "";
  38. int idUsuario = 0;
  39. int idConsumidor = 0;
  40. Consumidor consumidor = new Consumidor();
  41. String procedure = "";
  42. procedure = "{call LOGIN (" + 1 + "," + username + "," + password + ")}";
  43. Conexion cn = new Conexion();
  44. CallableStatement cs = null;
  45. cs = cn.conn(procedure);
  46. try {
  47. cs.execute();
  48. } catch (SQLException ex) {
  49. Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
  50. }
  51.  
  52. if (cs != null) {
  53. try {
  54. if (!cs.getString(1).isEmpty() && !cs.getString(2).isEmpty()
  55. && 1 <= Integer.parseInt(cs.getBigDecimal(3).toString())
  56. && 1 <= Integer.parseInt(cs.getBigDecimal(4).toString())) {
  57. nombre = cs.getString("nombre");
  58. password = cs.getString("ap_pat");
  59. idUsuario = Integer.parseInt(cs.getString("id_u"));
  60. idConsumidor = Integer.parseInt(cs.getString("id_c"));
  61. cn.getConecction().close();
  62. }
  63. } catch (SQLException ex) {
  64. Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
  65. System.out.println(ex);
  66. }
  67. }
  68. if (nombre != null && apellido != null && idUsuario >= 1 && idConsumidor >= 1) {
  69. consumidor.setNombres(nombre);
  70. consumidor.setApellidoPaterno(apellido);
  71. consumidor.setIdUsuario(usuarioFacade.find(BigDecimal.valueOf(idUsuario)));
  72. consumidor.setIdConsumidor(BigDecimal.valueOf(idConsumidor));
  73. HttpSession sesion = request.getSession();
  74. sesion.setAttribute("consumidor", consumidor);
  75. request.getRequestDispatcher("inicio.jsp")
  76. .forward(request, response);
  77.  
  78.  
  79. } else {
  80. request.getRequestDispatcher("./login.jsp")
  81. .forward(request, response);
  82. }
  83. }
Add Comment
Please, Sign In to add comment