Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- // datos de la conexion a la base de datos
- import java.sql.DriverManager;
- public class DbConnection {
- static String bd = "tienda";
- static String login = "root";
- static String password = "";
- static String url = "jdbc:mysql://localhost/" + bd;
- Connection conn = null;
- //realizando la conexion a la base de datos
- public DbConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(url, login, password);
- System.out.println("CONEXION A LA BASE DE DATOS "+bd+" FUE EXITOSA");
- }
- catch(Exception e)
- {
- System.out.println("NO SE PUEDE CONECTAR");
- }
- }
- //OBTENER CONEXION
- public Connection getConnection(){
- return conn;
- }
- // DESCONECCION DE LA BASE DE DATOS
- public void desconectar(){
- conn = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement