Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package conect_DB;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. public class Conexao {
  7.  
  8. public static java.sql.Connection conexao;
  9. private static String servidor = "jdbc:mysql://localhost:3306/ucsal";
  10.  
  11. public static boolean conectar() {
  12. try {
  13.  
  14. Class driverMysql = Class.forName("com.mysql.jdbc.Driver");
  15.  
  16. conexao = DriverManager.getConnection(servidor, "root", "");
  17.  
  18. if (conexao == null) {
  19. return false;
  20. }
  21. }
  22.  
  23. catch (ClassNotFoundException e) {
  24. System.out.println(e.getMessage() + " on method 'conectar' error");
  25. }
  26.  
  27. catch (SQLException e) {
  28. System.out.println(e.getMessage());
  29. }
  30.  
  31. return true;
  32. }
  33.  
  34. public static void desconectar() {
  35. try {
  36. conexao.close();
  37. }
  38.  
  39. catch (SQLException e) {
  40. System.out.println(e.getMessage());
  41. }
  42.  
  43. catch (NullPointerException e) {
  44. System.out.println("method 'close()' error. Not conection opened");
  45. }
  46. }
  47.  
  48. }
  49.  
  50. package servlets;
  51.  
  52. public class Server {
  53.  
  54.  
  55. }
  56.  
  57. <form name="form1" method="POST" action="Server">
  58.  
  59. //formulario aqui
  60.  
  61. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement