Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Conexao {
- Connection conexao = null;
- Statement stmt = null;
- String host, usr, pwd, db, con;
- public Conexao(String h, String u, String d) {
- host = h;
- usr = u;
- db = d;
- pwd = null;
- con = "jdbc:mysql://" + host + "/" + db;
- }
- public void conectar(String p) {
- try {
- String driver = "com.mysql.jdbc.Driver";
- Class.forName(driver);
- pwd = p;
- conexao = DriverManager.getConnection(con, usr, pwd);
- stmt = conexao.createStatement();
- System.out.println("Conexao estabilizada: " + conexao);
- } catch (ClassNotFoundException e) {
- System.out.println("Class not found");
- } catch (SQLException e) {
- System.out.println("SQL Exception");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement