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 Heisenberg;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Kevin Arnold
- */
- public class Conexion {
- public static Connection GetConnection()
- {
- Connection conexion=null;
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- String servidor = "jdbc:mysql://localhost/quimicas";
- String usuarioDB="user";
- String passwordDB="123";
- conexion= DriverManager.getConnection(servidor,usuarioDB,passwordDB);
- }
- catch(ClassNotFoundException ex)
- {
- JOptionPane.showMessageDialog(null, ex, "Error1 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
- conexion=null;
- }
- catch(SQLException ex)
- {
- JOptionPane.showMessageDialog(null, ex, "Error2 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
- conexion=null;
- }
- catch(Exception ex)
- {
- JOptionPane.showMessageDialog(null, ex, "Error3 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
- conexion=null;
- }
- finally
- {
- return conexion;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement