Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package conexao;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- *
- * @author Mario Jorge
- */
- public class Conexao {
- private Connection conexao = null;
- private boolean status = false;
- public Statement connect() throws SQLException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conexao = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/livraria?user=root&password=");
- status = true;
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- status = false;
- return null;
- } catch (SQLException ex) {
- ex.printStackTrace();
- status = false;
- return null;
- }
- return (Statement) conexao.createStatement();
- }
- public void disconect () {
- try {
- conexao.close();
- status = false;
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- public boolean isConnected() {
- return status;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement