Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.util;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Connection;
- public class Conexion {
- private Connection conexion;
- static String bd="Juego";
- static String user="root";
- static String password="";
- static String server="jdbc:mysql://localhost/"+bd;
- public void establecerConexion(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- conexion = DriverManager.getConnection(server,user,password);
- }
- catch(Exception e){
- System.out.println("Imposible realizar conexion con la BD");
- e.printStackTrace();
- }
- }
- public Connection getConexion(){
- return conexion;
- }
- public void cerrar(ResultSet rs){
- if(rs !=null){
- try{
- rs.close();
- }
- catch(Exception e){
- System.out.print("No es posible cerrar la Conexion");
- }
- }
- }
- public void cerrar(java.sql.Statement stmt){
- if(stmt !=null){
- try{
- stmt.close();
- }
- catch(Exception e){}
- }
- }
- public void cerrarConexion(){
- if(conexion !=null){
- try{
- conexion.close();
- }
- catch(Exception e){}
- }
- }
- }
Add Comment
Please, Sign In to add comment