Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package conect_DB;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class Conexao {
- public static java.sql.Connection conexao;
- private static String servidor = "jdbc:mysql://localhost:3306/ucsal";
- public static boolean conectar() {
- try {
- Class driverMysql = Class.forName("com.mysql.jdbc.Driver");
- conexao = DriverManager.getConnection(servidor, "root", "");
- if (conexao == null) {
- return false;
- }
- }
- catch (ClassNotFoundException e) {
- System.out.println(e.getMessage() + " on method 'conectar' error");
- }
- catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- return true;
- }
- public static void desconectar() {
- try {
- conexao.close();
- }
- catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- catch (NullPointerException e) {
- System.out.println("method 'close()' error. Not conection opened");
- }
- }
- }
- package servlets;
- public class Server {
- }
- <form name="form1" method="POST" action="Server">
- //formulario aqui
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement