Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package megaventa;
- import java.sql.*;
- import java.sql.DriverManager;
- /**
- *
- * @author Angel Nuñez
- */
- public class conexion {
- private static String username = "root";
- private static String password = "";
- private static String hostname = "localhost";
- private static String puerto = "3306";
- private static String database = "megaventa";
- private static String classname = "com.mysql.jdbc.Driver";
- private static String url = "jdbc:mysql://"+hostname+":"+puerto+"/"+database;
- private static Connection conn;
- public static Connection obtener() throws ClassNotFoundException, SQLException
- {
- if(conn==null)
- {
- Class.forName(classname);
- conn = DriverManager.getConnection(url, username, password);
- }
- return conn;
- }
- public conexion()
- {
- try {
- Class.forName(classname);
- conn = DriverManager.getConnection(url, username, password);
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
- public Connection getConnection()
- {
- return this.conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement