Advertisement
Guest User

Load into table from SQL Query

a guest
Nov 27th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package Heisenberg;
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.SQLException;
  10. import javax.swing.JOptionPane;
  11.  
  12. /**
  13.  *
  14.  * @author Kevin Arnold
  15.  */
  16. public class Conexion {
  17.      
  18.     public static Connection GetConnection()
  19.     {
  20.         Connection conexion=null;
  21.      
  22.         try
  23.         {
  24.             Class.forName("com.mysql.jdbc.Driver");
  25.             String servidor = "jdbc:mysql://localhost/quimicas";
  26.             String usuarioDB="user";
  27.             String passwordDB="123";
  28.             conexion= DriverManager.getConnection(servidor,usuarioDB,passwordDB);
  29.         }
  30.         catch(ClassNotFoundException ex)
  31.         {
  32.             JOptionPane.showMessageDialog(null, ex, "Error1 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  33.             conexion=null;
  34.         }
  35.         catch(SQLException ex)
  36.         {
  37.             JOptionPane.showMessageDialog(null, ex, "Error2 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  38.             conexion=null;
  39.         }
  40.         catch(Exception ex)
  41.         {
  42.             JOptionPane.showMessageDialog(null, ex, "Error3 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  43.             conexion=null;
  44.         }
  45.         finally
  46.         {
  47.             return conexion;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement